#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <complex>
#include <bitset>
#include <queue>
#include <cassert>

using namespace std;

//#define HOME
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define next _next
#define rank _rank
#define prev _prev
#define sz(s) int((s).size())

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef complex <double> tc;

const double eps = 1e-9;
const double pi = acos(double(-1));
const int inf = int(1e9);
const ll MOD = ll(1e9 + 7);

int sum[1000100];
char s[1000100];
ll suff[1000100];
ll d[1000100][2];

inline int get(int l, int r){
	if(l > r){
		return 0;
	}
	return sum[r] - (l > 0 ? sum[l - 1] : 0);
}

inline void norm(ll &a){
	while(a < 0){
		a += MOD;
	}
	while(a >= MOD){
		a -= MOD;
	}
}

inline ll calc(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b % 2 != 0){
			res = (res * a) % MOD;
		}
		a = (a * a) % MOD;
		b /= 2;
	}
	return res;
}

int main(){
#ifdef HOME
	double start = clock();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif
	int n, k;
	scanf("%d %d %s", &n, &k, s);
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'W');
	}
	for(int i = 0; i < n; i++){
		if(i - k + 1 >= 0 && get(i - k + 1, i) == 0 && (i - k < 0 || s[i - k] != 'B')){
			d[i][0] = (i - k - 1 >= 0 ? d[i - k - 1][1] : 1);
			norm(d[i][0]);
		}
		d[i][1] = (i > 0 ? d[i - 1][1] : 1) * (s[i] == 'X' ? 2 : 1) - d[i][0];
		norm(d[i][1]);
	}
	vector < pair <int, ll> > v1;
	for(int i = 0; i < n; i++){
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i == 0 || s[i - 1] != 'B')){
			v1.pb(mp(i, d[i + k - 1][0]));
		}
	}
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'B');
	}
	for(int i = n - 1; i >= 0; i--){
		d[i][0] = 0;
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i + k >= n || s[i + k] != 'W')){
			d[i][0] = (i + k + 1 < n ? d[i + k + 1][1] : 1);
			norm(d[i][0]);
		}
		d[i][1] = (i < n - 1 ? d[i + 1][1] : 1) * (s[i] == 'X' ? 2 : 1) - d[i][0];
		norm(d[i][1]);
	}
	vector < pair <int, ll> > v2;
	for(int i = 0; i < n; i++){
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i + k >= n || s[i + k] != 'W')){
			v2.pb(mp(i, d[i][0]));
		}
	}
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'X');
	}
	for(int i = sz(v2) - 1; i >= 0; i--){
		suff[i] = suff[i + 1] + (v2[i].sc * calc(2, (v2[i].fs > 0 ? sum[v2[i].fs - 1] : 0))) % MOD;
		norm(suff[i]);
	}
	ll ans = 0;
	for(int i = 0; i < sz(v1); i++){
		int pos = lower_bound(v2.begin(), v2.end(), mp(v1[i].fs + k, 0LL)) - v2.begin();
		if(pos < 0 || pos >= sz(v2)){
			continue;
		}
		ll res = (v1[i].sc * calc(calc(2, sum[v1[i].fs + k - 1]), MOD - 2)) % MOD;
		res = (res * suff[pos]) % MOD;
		ans += res;
		norm(ans);
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <complex>
#include <bitset>
#include <queue>
#include <cassert>

using namespace std;

//#define HOME
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define next _next
#define rank _rank
#define prev _prev
#define sz(s) int((s).size())

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef complex <double> tc;

const double eps = 1e-9;
const double pi = acos(double(-1));
const int inf = int(1e9);
const ll MOD = ll(1e9 + 7);

int sum[1000100];
char s[1000100];
ll suff[1000100];
ll d[1000100][2];

inline int get(int l, int r){
	if(l > r){
		return 0;
	}
	return sum[r] - (l > 0 ? sum[l - 1] : 0);
}

inline void norm(ll &a){
	while(a < 0){
		a += MOD;
	}
	while(a >= MOD){
		a -= MOD;
	}
}

inline ll calc(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b % 2 != 0){
			res = (res * a) % MOD;
		}
		a = (a * a) % MOD;
		b /= 2;
	}
	return res;
}

pair <int, ll> v1[1000100], v2[1000100];

int main(){
#ifdef HOME
	double start = clock();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif
	int n, k;
	scanf("%d %d %s", &n, &k, s);
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'W');
	}
	for(int i = 0; i < n; i++){
		if(i - k + 1 >= 0 && get(i - k + 1, i) == 0 && (i - k < 0 || s[i - k] != 'B')){
			d[i][0] = (i - k - 1 >= 0 ? d[i - k - 1][1] : 1);
			norm(d[i][0]);
		}
		d[i][1] = (i > 0 ? d[i - 1][1] : 1) * (s[i] == 'X' ? 2 : 1) - d[i][0];
		norm(d[i][1]);
	}
	int k1 = 0;
	for(int i = 0; i < n; i++){
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i == 0 || s[i - 1] != 'B')){
			v1[k1++] = mp(i, d[i + k - 1][0]);
		}
	}
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'B');
	}
	for(int i = n - 1; i >= 0; i--){
		d[i][0] = 0;
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i + k >= n || s[i + k] != 'W')){
			d[i][0] = (i + k + 1 < n ? d[i + k + 1][1] : 1);
			norm(d[i][0]);
		}
		d[i][1] = (i < n - 1 ? d[i + 1][1] : 1) * (s[i] == 'X' ? 2 : 1) - d[i][0];
		norm(d[i][1]);
	}
	int k2 = 0;
	for(int i = 0; i < n; i++){
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i + k >= n || s[i + k] != 'W')){
			v2[k2++] = mp(i, d[i][0]);
		}
	}
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'X');
	}
	for(int i = k2 - 1; i >= 0; i--){
		suff[i] = suff[i + 1] + (v2[i].sc * calc(2, (v2[i].fs > 0 ? sum[v2[i].fs - 1] : 0))) % MOD;
		norm(suff[i]);
	}
	ll ans = 0;
	int pos = 0;
	for(int i = 0; i < k1; i++){
		while(pos < k2 && v2[pos].fs <= v1[i].fs + k - 1){
			pos++;
		}
		if(pos < 0 || pos >= k2){
			continue;
		}
		ll res = (v1[i].sc * calc(calc(2, sum[v1[i].fs + k - 1]), MOD - 2)) % MOD;
		res = (res * suff[pos]) % MOD;
		ans += res;
		norm(ans);
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <complex>
#include <bitset>
#include <queue>
#include <cassert>

using namespace std;

//#define HOME
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define next _next
#define rank _rank
#define prev _prev
#define sz(s) int((s).size())

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef complex <double> tc;

const double eps = 1e-9;
const double pi = acos(double(-1));
const int inf = int(1e9);
const ll MOD = ll(1e9 + 7);

int sum[1000100];
char s[1000100];
ll suff[1000100];
ll d[1000100][2];

inline int get(int l, int r){
	if(l > r){
		return 0;
	}
	return sum[r] - (l > 0 ? sum[l - 1] : 0);
}

inline void norm(ll &a){
	while(a < 0){
		a += MOD;
	}
	while(a >= MOD){
		a -= MOD;
	}
}

inline ll calc(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b % 2 != 0){
			res = (res * a) % MOD;
		}
		a = (a * a) % MOD;
		b /= 2;
	}
	return res;
}

int main(){
#ifdef HOME
	double start = clock();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
	int n, k;
	scanf("%d %d %s", &n, &k, s);
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'W');
	}
	for(int i = 0; i < n; i++){
		if(i - k + 1 >= 0 && get(i - k + 1, i) == 0 && (i - k < 0 || s[i - k] != 'B')){
			d[i][0] = (i - k - 1 >= 0 ? d[i - k - 1][1] : 1);
			norm(d[i][0]);
		}
		d[i][1] = (i > 0 ? d[i - 1][1] : 1) * (s[i] == 'X' ? 2 : 1) - d[i][0];
		norm(d[i][1]);
	}
	vector < pair <int, ll> > v1;
	for(int i = 0; i < n; i++){
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i == 0 || s[i - 1] != 'B')){
			v1.pb(mp(i, d[i + k - 1][0]));
		}
	}
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'B');
	}
	for(int i = n - 1; i >= 0; i--){
		d[i][0] = 0;
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i + k >= n || s[i + k] != 'W')){
			d[i][0] = (i + k + 1 < n ? d[i + k + 1][1] : 1);
			norm(d[i][0]);
		}
		d[i][1] = (i < n - 1 ? d[i + 1][1] : 1) * (s[i] == 'X' ? 2 : 1) - d[i][0];
		norm(d[i][1]);
	}
	vector < pair <int, ll> > v2;
	for(int i = 0; i < n; i++){
		if(i + k - 1 < n && get(i, i + k - 1) == 0 && (i + k >= n || s[i + k] != 'W')){
			v2.pb(mp(i, d[i][0]));
		}
	}
	for(int i = 0; i < n; i++){
		sum[i] = (i > 0 ? sum[i - 1] : 0) + (s[i] == 'X');
	}
	for(int i = sz(v2) - 1; i >= 0; i--){
		suff[i] = suff[i + 1] + (v2[i].sc * calc(2, (v2[i].fs > 0 ? sum[v2[i].fs - 1] : 0))) % MOD;
		norm(suff[i]);
	}
	ll ans = 0;
	for(int i = 0; i < sz(v1); i++){
		int pos = lower_bound(v2.begin(), v2.end(), mp(v1[i].fs + k, 0LL)) - v2.begin();
		if(pos < 0 || pos >= sz(v2)){
			continue;
		}
		ll res = (v1[i].sc * calc(calc(2, sum[v1[i].fs + k - 1]), MOD - 2)) % MOD;
		res = (res * suff[pos]) % MOD;
		ans += res;
		norm(ans);
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
using namespace std;
#define mo 1000000007
int k,n;
char s[1000013];
long long int dp1[1000013];
long long int dp2[1000013];
long long int calc[1000013];
int main()
{
    scanf("%d%d%s",&n,&k,s+1);
    int form=n+1;
    dp2[n+1]=1;calc[n+1]=1;
    for(int i=n;i>=1;i--)
    {
        if(s[i]=='X')
        {
            dp2[i]=dp2[i+1]<<1;
            calc[i]=calc[i+1]<<1;
        }
        else
        {
            dp2[i]=dp2[i+1];
            calc[i]=calc[i+1];
        }
        dp2[i]=dp2[i]%mo;
        calc[i]=calc[i]%mo;
        if(s[i]=='B')   form=i;
        if(form>=i+k && (i+k==n+1 || s[i+k]!='W')) dp2[i]=(dp2[i]-(i+k==n+1?1:dp2[i+k+1])+mo)%mo;
    }
    form=0;
    dp1[0]=1;
    long long int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='X')   dp1[i]=dp1[i-1]<<1;
        else dp1[i]=dp1[i-1];
        dp1[i]=dp1[i]%mo;
        if(s[i]=='W')   form=i;
        if(form<=i-k && (i-k==0 || s[i-k]!='B'))
        {
            dp1[i]=(dp1[i]-(i-k==0?1:dp1[i-k-1])+mo)%mo;
            if(i>=k && i+k-1<=n)
                ans=(ans+(i-k==0?1:dp1[i-k-1])*(calc[i+1]-dp2[i+1])+mo)%mo;
        }
    }
    cout<<(ans+mo)%mo<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
using namespace std;
#define mo 1000000007
int k,n;
char s[1000003];
long long int dp1[1000003];
long long int dp2[1000003];
long long int calc[1000003];
bool used[1000001];
int main()
{
    scanf("%d%d%s",&n,&k,s+1);
    int form=n+1;
    dp2[n+1]=1;calc[n+1]=1;
    for(int i=n;i>=1;i--)
    {
        if(s[i]=='X')
        {
            dp2[i]=dp2[i+1]<<1;
            calc[i]=calc[i+1]<<1;
        }
        else
        {
            dp2[i]=dp2[i+1];
            calc[i]=calc[i+1];
        }
        if(s[i]=='B')   form=i;
        if(form>=i+k && (i+k==n+1 || s[i+k]!='W')) dp2[i]=(dp2[i]-(i+k==n+1?1:dp2[i+k+1])+mo)%mo;
    }
    form=0;
    dp1[0]=1;
    long long int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='X')   dp1[i]=dp1[i-1]<<1;
        else dp1[i]=dp1[i-1];
        if(s[i]=='W')   form=i;
        if(form<=i-k && (i-k==0 || s[i-k]!='B'))
        {
            dp1[i]=(dp1[i]-(i-k==0?1:dp1[i-k-1])+mo)%mo;
            if(i>=k && i+k-1<=n)
                ans=(ans+(i-k==0?1:dp1[i-k-1])*(calc[i+1]-dp2[i+1])+mo)%mo;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;

const int maxn = 1000005, MOD = 1000000007;
int n, limit;
LL Pow[maxn], L[maxn], R[maxn];
char pat[maxn];

int main() {
	Pow[0] = 1;
	for (int i = 1; i < maxn; i++)
		Pow[i] = Pow[i - 1] * 2 % MOD;

	while (~scanf("%d %d", &n, &limit)) {
		scanf("%s", pat + 1);

		LL cntX = 0, cntW = 0, sumL = 0, dec = 0;	// num of X in [1,i-limit], num of W, sum of L is [i-limit+1,i]
		for (int i = 1; i <= n; i++) {
			cntW += pat[i] == 'W';
			if (i > limit) cntW -= pat[i - limit] == 'W';

			if (i > limit) cntX += pat[i - limit] == 'X';

			if (i > 1) sumL = (sumL + L[i - 1]) % MOD;
			if (i > limit) sumL = (sumL - L[i - limit] + MOD) % MOD;

			if (i > limit && pat[i - limit] == 'X') dec = dec * 2 % MOD;
			if (i > limit) dec = (dec + L[i - limit]) % MOD;

			if (i >= limit && cntW == 0) L[i] = (Pow[cntX] - sumL - dec + MOD) % MOD;
			else L[i] = 0;
		}

		LL cntB = 0, sumR = 0;	cntX = 0, dec = 0;
		for (int i = n; i >= 1; i--) {
			cntB += pat[i] == 'B';
			if (i + limit <= n) cntB -= pat[i + limit] == 'B';

			if (i + limit <= n) cntX += pat[i + limit] == 'X';

			if (i < n) sumR = (sumR + R[i + 1]) % MOD;
			if (i + limit <= n) sumR = (sumR - R[i + limit] + MOD) % MOD;

			if (i + limit<=n && pat[i + limit] == 'X') dec = dec * 2 % MOD;
			if (i + limit<=n) dec = (dec + R[i + limit]) % MOD;

			if (i + limit - 1 <= n && cntB == 0) R[i] = (Pow[cntX] - sumR - dec + MOD) % MOD;
			else R[i] = 0;
		}

		LL res = 0, sum = 0;
		for (int i = n; i >= 1; i--) {
			res = (res + L[i] * sum) % MOD;
			if (pat[i] == 'X') sum = sum * 2 % MOD;
			sum = (sum + R[i]) % MOD;
		}

		printf("%d\n", (int) res);
	}
	return 0;
}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;

const int maxn = 10005, MOD = 1000000007;
int n, limit;
LL Pow[maxn], L[maxn], R[maxn];
char pat[maxn];

int main() {
	Pow[0] = 1;
	for (int i = 1; i < maxn; i++)
		Pow[i] = Pow[i - 1] * 2 % MOD;

	while (~scanf("%d %d", &n, &limit)) {
		scanf("%s", pat + 1);

		LL cntX = 0, cntW = 0, sumL = 0, dec = 0;	// num of X in [1,i-limit], num of W, sum of L is [i-limit+1,i]
		for (int i = 1; i <= n; i++) {
			cntW += pat[i] == 'W';
			if (i > limit) cntW -= pat[i - limit] == 'W';

			if (i > limit) cntX += pat[i - limit] == 'X';

			if (i > 1) sumL = (sumL + L[i - 1]) % MOD;
			if (i > limit) sumL = (sumL - L[i - limit] + MOD) % MOD;

			if (i > limit && pat[i - limit] == 'X') dec = dec * 2 % MOD;
			if (i > limit) dec = (dec + L[i - limit]) % MOD;

			if (i >= limit && cntW == 0) L[i] = (Pow[cntX] - sumL - dec + MOD) % MOD;
			else L[i] = 0;
		}

		LL cntB = 0, sumR = 0;	cntX = 0, dec = 0;
		for (int i = n; i >= 1; i--) {
			cntB += pat[i] == 'B';
			if (i + limit <= n) cntB -= pat[i + limit] == 'B';

			if (i + limit <= n) cntX += pat[i + limit] == 'X';

			if (i < n) sumR = (sumR + R[i + 1]) % MOD;
			if (i + limit <= n) sumR = (sumR - R[i + limit] + MOD) % MOD;

			if (i + limit<=n && pat[i + limit] == 'X') dec = dec * 2 % MOD;
			if (i + limit<=n) dec = (dec + R[i + limit]) % MOD;

			if (i + limit - 1 <= n && cntB == 0) R[i] = (Pow[cntX] - sumR - dec + MOD) % MOD;
			else R[i] = 0;
		}

		LL res = 0, sum = 0;
		for (int i = n; i >= 1; i--) {
			res = (res + L[i] * sum) % MOD;
			if (pat[i] == 'X') sum = sum * 2 % MOD;
			sum = (sum + R[i]) % MOD;
		}

		printf("%d\n", (int) res);
	}
	return 0;
}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;

const int maxn = 100005, MOD = 1000000007;
int n, limit;
LL Pow[maxn], L[maxn], R[maxn];
char pat[maxn];

int main() {
	Pow[0] = 1;
	for (int i = 1; i < maxn; i++)
		Pow[i] = Pow[i - 1] * 2 % MOD;

	while (~scanf("%d %d", &n, &limit)) {
		scanf("%s", pat + 1);

		LL cntX = 0, cntW = 0, sumL = 0, dec = 0;	// num of X in [1,i-limit], num of W, sum of L is [i-limit+1,i]
		for (int i = 1; i <= n; i++) {
			cntW += pat[i] == 'W';
			if (i > limit) cntW -= pat[i - limit] == 'W';

			if (i > limit) cntX += pat[i - limit] == 'X';

			if (i > 1) sumL = (sumL + L[i - 1]) % MOD;
			if (i > limit) sumL = (sumL - L[i - limit] + MOD) % MOD;

			if (i > limit && pat[i - limit] == 'X') dec = dec * 2 % MOD;
			if (i > limit) dec = (dec + L[i - limit]) % MOD;

			if (i >= limit && cntW == 0) L[i] = (Pow[cntX] - sumL - dec + MOD) % MOD;
			else L[i] = 0;
		}

		LL cntB = 0, sumR = 0;	cntX = 0, dec = 0;
		for (int i = n; i >= 1; i--) {
			cntB += pat[i] == 'B';
			if (i + limit <= n) cntB -= pat[i + limit] == 'B';

			if (i + limit <= n) cntX += pat[i + limit] == 'X';

			if (i < n) sumR = (sumR + R[i + 1]) % MOD;
			if (i + limit <= n) sumR = (sumR - R[i + limit] + MOD) % MOD;

			if (i + limit<=n && pat[i + limit] == 'X') dec = dec * 2 % MOD;
			if (i + limit<=n) dec = (dec + R[i + limit]) % MOD;

			if (i + limit - 1 <= n && cntB == 0) R[i] = (Pow[cntX] - sumR - dec + MOD) % MOD;
			else R[i] = 0;
		}

		LL res = 0, sum = 0;
		for (int i = n; i >= 1; i--) {
			res = (res + L[i] * sum) % MOD;
			if (pat[i] == 'X') sum = sum * 2 % MOD;
			sum = (sum + R[i]) % MOD;
		}

		printf("%d\n", (int) res);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <vector>
#include <valarray>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <sstream>
#include <complex>
#include <iomanip>
#include <cassert>

#define show(x) cerr << "# " << #x << " = " << x << endl

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define SZ(x) ((int)x.size())
#define PB push_back
#define F first
#define S second
#define X real()
#define Y imag()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef complex<double> point;

const int MAXN = 1000 * 1000 + 10;
const int MOD = 1000000007;

int n, k;
string s;

ll fre[MAXN];
ll freb[MAXN], frew[MAXN];

ll can[MAXN];
ll canb[MAXN], canw[MAXN];

void pre()
{
	ll lw = 0;
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == 'W')
			lw = i;
		can[i] = (((i - lw) >= k) && (s[i - k] != 'B'));
	}

	fre[0] = 1;
	for(int i = 1; i <= n; i++)
	{
		fre[i] = fre[i - 1] * (s[i] == 'X' ? 2 : 1);
		if(can[i])
			fre[i] -= (i - k - 1 < 0) ? 1 : fre[i - k - 1];
		fre[i] %= MOD;
	}
}

void invert(string &s)
{
	reverse(s.begin(), s.end());
	FOR(i, SZ(s))
		if(s[i] == 'W' || s[i] == 'B')
			s[i] = 'W' + 'B' - s[i];
}

void solve()
{
	s = " " + s + " ";
	pre();
	invert(s);
	for(int i = 0; i <= n + 1; i++)
	{
		freb[i] = fre[i];
		canb[i] = can[i];
	}

	pre();
	invert(s);
	for(int i = 0; i <= n + 1; i++)
	{
		frew[i] = fre[n - i + 1];
		canw[i] = can[n - i + 1];
	}

	ll sumw = 0;
	ll ans = 0;
	for(int i = n; i >= 1; i--)
	{
		sumw = sumw * (s[i] == 'X' ? 2 : 1) + canw[i] * (i + k + 1 <= n + 1 ? frew[i + k + 1] : 1);
		sumw %= MOD;
		ans += sumw * (canb[i - 1] * (i - k - 2 >= 0 ? freb[i - k - 2] : 1));
		ans %= MOD;
	}
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> n >> k;
	cin >> s;

	solve();

	return 0;
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <vector>
#include <valarray>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <sstream>
#include <complex>
#include <iomanip>
#include <cassert>

#define show(x) cerr << "# " << #x << " = " << x << endl

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define SZ(x) ((int)x.size())
#define PB push_back
#define F first
#define S second
#define X real()
#define Y imag()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef complex<double> point;

const int MAXN = 1000 * 1000 + 10;
const int MOD = 1000000007;

int n, k;
string s;

ll fre[MAXN];
ll freb[MAXN], frew[MAXN];

ll can[MAXN];
ll canb[MAXN], canw[MAXN];

ll mod(ll x, ll m)
{
	return ((x % m) + m) % m;
}

void pre()
{
	ll lw = 0;
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == 'W')
			lw = i;
		can[i] = (((i - lw) >= k) && (s[i - k] != 'B'));
	}

	fre[0] = 1;
	for(int i = 1; i <= n; i++)
	{
		fre[i] = fre[i - 1] * (s[i] == 'X' ? 2 : 1);
		if(can[i])
			fre[i] -= (i - k - 1 < 0) ? 1 : fre[i - k - 1];
		fre[i] = mod(fre[i], MOD);
	}
}

void invert(string &s)
{
	reverse(s.begin(), s.end());
	FOR(i, SZ(s))
		if(s[i] == 'W' || s[i] == 'B')
			s[i] = 'W' + 'B' - s[i];
}

void solve()
{
	s = " " + s + " ";
	pre();
	invert(s);
	for(int i = 0; i <= n + 1; i++)
	{
		freb[i] = fre[i];
		canb[i] = can[i];
	}

	pre();
	invert(s);
	for(int i = 0; i <= n + 1; i++)
	{
		frew[i] = fre[n - i + 1];
		canw[i] = can[n - i + 1];
	}

	ll sumw = 0;
	ll ans = 0;
	for(int i = n; i >= 1; i--)
	{
		sumw = sumw * (s[i] == 'X' ? 2 : 1) + canw[i] * (i + k + 1 <= n + 1 ? frew[i + k + 1] : 1);
		sumw %= MOD;
		ans += sumw * (canb[i - 1] * (i - k - 2 >= 0 ? freb[i - k - 2] : 1));
		ans %= MOD;
	}
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> n >> k;
	cin >> s;

	solve();

	return 0;
}


#include <iostream>
#include <algorithm>
#include <fstream>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <vector>
#include <valarray>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <sstream>
#include <complex>
#include <iomanip>
#include <cassert>

#define show(x) cerr << "# " << #x << " = " << x << endl

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define SZ(x) ((int)x.size())
#define PB push_back
#define F first
#define S second
#define X real()
#define Y imag()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef complex<double> point;

const int MAXN = 1000 * 1000 + 10;
const int MOD = 1000000007;

int n, k;
string s;

ll fre[MAXN];
ll freb[MAXN], frew[MAXN];

ll can[MAXN];
ll canb[MAXN], canw[MAXN];

void pre()
{
	ll lw = 0;
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == 'W')
			lw = i;
		can[i] = (((i - lw) >= k) && (s[i - k] != 'B'));
	}

	fre[0] = 1;
	for(int i = 1; i <= n; i++)
	{
		fre[i] = fre[i - 1] * (s[i] == 'X' ? 2 : 1);
		if(can[i])
			fre[i] -= (i - k - 1 < 0) ? 1 : fre[i - k - 1];
	}
}

void invert(string &s)
{
	reverse(s.begin(), s.end());
	FOR(i, SZ(s))
		if(s[i] == 'W' || s[i] == 'B')
			s[i] = 'W' + 'B' - s[i];
}

void solve()
{
	s = " " + s + " ";
	pre();
	invert(s);
	for(int i = 0; i <= n + 1; i++)
	{
		freb[i] = fre[i];
		canb[i] = can[i];
	}

	pre();
	invert(s);
	for(int i = 0; i <= n + 1; i++)
	{
		frew[i] = fre[n - i + 1];
		canw[i] = can[n - i + 1];
	}

	ll sumw = 0;
	ll ans = 0;
	for(int i = n; i >= 1; i--)
	{
		sumw = sumw * (s[i] == 'X' ? 2 : 1) + canw[i] * (i + k + 1 <= n + 1 ? frew[i + k + 1] : 1);
		sumw %= MOD;
		ans += sumw * (canb[i - 1] * (i - k - 2 >= 0 ? freb[i - k - 2] : 1));
		ans %= MOD;
	}
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> n >> k;
	cin >> s;

	solve();

	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

#define MOD 1000000007

string S;
int DP[1000010];
int psumx[1000010];
int psumb[1000010];
int psumw[1000010];
int POW2[1000010];

int derl[1000010];
int derr[1000010];

void partials(int N) {
  psumx[0] = psumb[0] = psumw[0] = 0;
  for(int i = 0; i < N; i++) {
    psumx[i + 1] = psumx[i] + (S[i] == 'X' ? 1 : 0);
    psumb[i + 1] = psumb[i] + (S[i] == 'B' ? 1 : 0);
    psumw[i + 1] = psumw[i] + (S[i] == 'W' ? 1 : 0);
  }
}

void calc_der(int* der, int N, int K, char loc, char rem) {
  partials(N);
  der[0] = 1;
  int run = 1;
  int sz = 1;
  for(int i = 0; i < N; i++) {
    if(S[i] == rem) {
      sz = 1;
    } else {
      sz++;
      if(S[i] == 'X') {
        run += der[i];
      }
    }
    if(sz > K) {
      run -= i - K + 1 == 0 ? 1 :
          (S[i - K] == loc ? 0 : der[i - K]);
      sz--;
    }
    der[i + 1] = run;
  }
}

int main() {
  int N, K; cin >> N >> K;
  cin >> S;

  for(int i = POW2[0] = 1; i <= N; i++) {
    POW2[i] = 2 * POW2[i - 1];
    if(POW2[i] >= MOD) POW2[i] -= MOD;
  }

  reverse(S.begin(), S.end());
  calc_der(derr, N, K, 'W', 'B');
  reverse(S.begin(), S.end());
  calc_der(derl, N, K, 'B', 'W');
  reverse(derr, derr + N + 1);

  int res = 0;
  int lft = 0;
  for(int i = K; i + K <= N; i++) {
    if(S[i - 1] == 'X') lft = (lft * 2) % MOD;

    if(psumw[i - K] == psumw[i] && (i - K == 0 || S[i - K - 1] != 'B')) {
      lft = (lft + (i - K == 0 ? 1 : derl[i - K - 1])) % MOD;
    }

    if(psumb[i + K] != psumb[i]) continue;
    if(i + K < N && S[i + K] == 'W') continue;

    res = (res + 1ll * lft * (i + K < N ? derr[i + K + 1] : 1)) % MOD;
  }

  cout << res << endl;
}


#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

#define MOD 1000000007

string S;
int DP[1000010];
int psumx[1000010];
int psumb[1000010];
int psumw[1000010];
int POW2[1000010];

int derl[1000010];
int derr[1000010];

void partials(int N) {
  psumx[0] = psumb[0] = psumw[0] = 0;
  for(int i = 0; i < N; i++) {
    psumx[i + 1] = psumx[i] + (S[i] == 'X' ? 1 : 0);
    psumb[i + 1] = psumb[i] + (S[i] == 'B' ? 1 : 0);
    psumw[i + 1] = psumw[i] + (S[i] == 'W' ? 1 : 0);
  }
}

void calc_der(int* der, int N, int K, char loc, char rem) {
  partials(N);
  der[0] = 1;
  int run = 1;
  int sz = 1;
  for(int i = 0; i < N; i++) {
    if(S[i] == rem) {
      sz = 1;
    } else {
      sz++;
      if(S[i] == 'X') {
        run += der[i];
        if(run >= MOD) run -= MOD;
      }
    }
    if(sz > K) {
      run -= i - K + 1 == 0 ? 1 :
          (S[i - K] == loc ? 0 : der[i - K]);
      if(run < 0) run += MOD;
      sz--;
    }
    der[i + 1] = run;
  }
}

int main() {
  int N, K; cin >> N >> K;
  cin >> S;

  for(int i = POW2[0] = 1; i <= N; i++) {
    POW2[i] = 2 * POW2[i - 1];
    if(POW2[i] >= MOD) POW2[i] -= MOD;
  }

  reverse(S.begin(), S.end());
  calc_der(derr, N, K, 'W', 'B');
  reverse(S.begin(), S.end());
  calc_der(derl, N, K, 'B', 'W');
  reverse(derr, derr + N + 1);

  int res = 0;
  int lft = 0;
  for(int i = K; i + K <= N; i++) {
    if(S[i - 1] == 'X') lft = (lft * 2) % MOD;

    if(psumw[i - K] == psumw[i] && (i - K == 0 || S[i - K - 1] != 'B')) {
      lft = (lft + (i - K == 0 ? 1 : derl[i - K - 1])) % MOD;
    }

    if(psumb[i + K] != psumb[i]) continue;
    if(i + K < N && S[i + K] == 'W') continue;

    res = (res + 1ll * lft * (i + K < N ? derr[i + K + 1] : 1)) % MOD;
  }

  cout << res << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 1000100
#define rep(i, a, b) for (int i = (a); i < (b); i ++)
#define clr(a, b) memset(a, b, sizeof(a))
#define eps 1e-10
#define inf 1000000000
#define MOD 1000000007

typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;

int N, K;
char str[NN];
INT po[NN];

int f[NN], p[NN];
int x[NN];

void calc(char* s, INT* c) {
	memset(x, 0, sizeof(x));
	int ct;
	INT val;
	if (s[0] == 'W') f[0] = 0;
	else f[0] = -1;
	for (int i = 1; i < N; i ++)
		if (s[i] == 'W') f[i] = i;
		else f[i] = f[i - 1];

	ct = 0;
	val = 0;
	for (int i = 0; i < N; i ++) {
		if (i) x[i] = x[i - 1];

		if (s[i] == 'X') {
			val = val * 2 % MOD;
			x[i] ++;
		}
		if (i - f[i] >= K && (i == K - 1 || s[i - K] != 'B')) {
			if (i <= K) val = (val + 1) % MOD;
			else val = (val + po[x[i - K - 1]] - c[i - K - 1] + MOD) % MOD;
		}
		c[i] = val;
	}
	return ;
}

INT a[NN], b[NN];
char s[NN];
int poss[NN], fir[NN];

int main() {

	int ct;
	INT ans, val;
	po[0] = 1;
	for (int i = 1; i < NN; i ++) po[i] = po[i - 1] * 2 % MOD;

	scanf("%d%d", &N, &K);
	scanf("%s", str);
	if (str[N - 1] == 'W') fir[N - 1] = N - 1;
	else fir[N - 1] = N;
	for (int i = N - 2; i >= 0; i --) {
		if (str[i] == 'W') fir[i] = i;
		else fir[i] = fir[i + 1];
	}

	strcpy(s, str);
	calc(s, a);

	reverse(s, s + N);
	for (int i = 0; i < N; i ++)
		if (s[i] == 'W') s[i] = 'B';
		else if (s[i] == 'B') s[i] = 'W';

	calc(s, b);

	ct = 0;
	for (int i = 0; i < N; i ++) {
		if (str[i] == 'X') ct ++;
		a[i] = (po[ct] - a[i] + MOD) % MOD;
	}

	for (int i = 0; i < N; i ++) {
		if (i == 0 || str[i - 1] != 'B') {
			if (fir[i] - i >= K) poss[i] = 1;
		}
	}

	ans = 0;
	for (int i = 0; i < N; i ++) {
		if (poss[i] == 0) continue ;
		if (i < 2) val = 1;
		else val = a[i - 2];
		if (i + K < N) val = val * b[N - i - K - 1] % MOD;
		else val = 0;
		ans = (ans + val) % MOD;
	}
	printf("%I64d\n", ans);

	return 0;
}


#include <cassert>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int N, K;
const int MAXN = 1000000;
char S[MAXN+1];
const int mod = 1000000007;
int waysB[MAXN], waysW[MAXN], totalW[MAXN];
int total_ways[MAXN];
int cntA[MAXN+1], cntB[MAXN+1];
int add(int a, int b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
    return a;
}
int sub(int a, int b) {
    a -= b;
    if (a < 0) {
        a += mod;
    }
    return a;
}
void calc(char need, int *ways) {
    for (int i=0; i<N; ++i) {
        cntA[i+1] = cntA[i];
        cntB[i+1] = cntB[i];
        if (S[i] == need) {
            ++cntA[i+1];
        } else if (S[i] != 'X') {
            ++cntB[i+1];
        }
    }
    for (int i=0; i+1<K; ++i) {
        total_ways[i] = i>0 ? total_ways[i-1] : 1;
        if (S[i] == 'X') {
            total_ways[i] = add(total_ways[i], total_ways[i]);
        }
        ways[i] = 0;
    }
    for (int i=K-1; i<N; ++i) {
        total_ways[i] = i>0 ? total_ways[i-1] : 1;
        if (S[i] == 'X') {
            total_ways[i] = add(total_ways[i], total_ways[i]);
        }

        ways[i] = i>0 ? ways[i-1] : 0;
        if (S[i] == 'X') {
            ways[i] = add(ways[i], ways[i]);
        }
        totalW[i] = i>0 ? totalW[i-1] : 0;
        if (S[i] == 'X') {
            totalW[i] = add(totalW[i], totalW[i]);
        }
        if (need == 'W') {
            ways[i] = 0; // for 'W' compute only the ways to end exactly on K Ws
        }

        if (i-K>=0 && S[i-K]==need) continue;
        int other = cntB[i+1] - cntB[i-K+1];
        if (other == 0) {
            int prev = 1;
            if (i-K >= 0) {
                assert(S[i-K] != need);
                if (i-K-1 >= 0) {
                    prev = sub(total_ways[i-K-1], totalW[i-K-1]);
                }
            }
            ways[i] = add(ways[i], prev);
            totalW[i] = add(totalW[i], prev);
        }

        if (need == 'B') {
            assert(ways[i] == totalW[i]);
        }
    }
}

char T[MAXN+1];
int g(int n) {
    for (int i=0; i<n; ++i) {
        if (T[i] == 'B') {
            return 1;
        }
    }
    return 0;
}
int f(int n) {
    int cnt = 0;
    for (int i=0; i<n; ++i) {
        if (S[i] == 'X')
            ++cnt;
    }
    memcpy(T, S, sizeof T);
    int ret = 0;
    for (int mask=0; mask<(1<<cnt); ++mask) {
        int j = 0;
        for (int i=0; i<n; ++i) {
            if (S[i] == 'X') {
                if (mask & (1<<j)) {
                    T[i] = 'B';
                } else {
                    T[i] = 'W';
                }
                ++j;
            }
        }
        //cerr << cnt << ' ' << mask << ' ' << string(T, T+n) << ' ' << g(n) << '\n';
        ret += g(n);
    }
    return ret;
}

int bar(int n) {
    if (T[n-1] != 'W')
        return 0;
    for (int i=0; i+1<n; ++i) {
        if (T[i] == 'W') {
            return 0;
        }
    }
    return 1;
}
int foo(int n) {
    int cnt = 0;
    for (int i=0; i<n; ++i) {
        if (S[i] == 'X')
            ++cnt;
    }
    memcpy(T, S, sizeof T);
    int ret = 0;
    for (int mask=0; mask<(1<<cnt); ++mask) {
        int j = 0;
        for (int i=0; i<n; ++i) {
            if (S[i] == 'X') {
                if (mask & (1<<j)) {
                    T[i] = 'B';
                } else {
                    T[i] = 'W';
                }
                ++j;
            }
        }
        //cerr << cnt << ' ' << mask << ' ' << string(T, T+n) << ' ' << bar(n) << '\n';
        ret += bar(n);
    }
    return ret;
}
int main() {
    scanf("%d %d", &N, &K);
    scanf("%s", S);
    calc('B', waysB);
    reverse(S, S+N);
    calc('W', waysW);
    //reverse(S, S+N);

    /*
    for (int i=0; i<N; ++i) {
        cerr << i << ' ' << waysB[i] << ' ' << f(i+1) << '\n';
    }
    */
    /*
    for (int i=0; i<N; ++i) {
        cerr << i << ' ' << waysW[i] << ' ' << foo(i+1) << '\n';
    }
    for (int i=0; i<N; ++i) {
        cerr << i << ' ' << total_ways[i] << ' ' << totalW[i] << '\n';
    }
    */

    long long sol = 0;
    for (int i=K-1; i+K<N; ++i) {
        sol = (sol + (long long)waysB[i]*waysW[N-i-2])%mod;
    }
    printf("%d\n", int(sol));
    return 0;
}


#include <cassert>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int N, K;
const int MAXN = 1000000;
char S[MAXN+1];
const int mod = 1000000007;
int waysB[MAXN], waysW[MAXN], totalW[MAXN];
int total_ways[MAXN];
int cntA[MAXN+1], cntB[MAXN+1];
int add(int a, int b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
    return a;
}
int sub(int a, int b) {
    a -= b;
    if (a < 0) {
        a += mod;
    }
    return a;
}
void calc(char need, int *ways) {
    for (int i=0; i<N; ++i) {
        cntA[i+1] = cntA[i];
        cntB[i+1] = cntB[i];
        if (S[i] == need) {
            ++cntA[i+1];
        } else if (S[i] != 'X') {
            ++cntB[i+1];
        }
    }
    for (int i=0; i+1<K; ++i) {
        total_ways[i] = i>0 ? total_ways[i-1] : 1;
        if (S[i] == 'X') {
            total_ways[i] = add(total_ways[i], total_ways[i]);
        }
        ways[i] = 0;
    }
    for (int i=K-1; i<N; ++i) {
        total_ways[i] = i>0 ? total_ways[i-1] : 1;
        if (S[i] == 'X') {
            total_ways[i] = add(total_ways[i], total_ways[i]);
        }

        ways[i] = i>0 ? ways[i-1] : 0;
        if (S[i] == 'X') {
            ways[i] = add(ways[i], ways[i]);
        }
        totalW[i] = ways[i];
        if (need == 'W') {
            ways[i] = 0; // for 'W' compute only the ways to end exactly on K Ws
        }

        if (i-K>=0 && S[i-K]==need) continue;
        int other = cntB[i+1] - cntB[i-K+1];
        if (other == 0) {
            int prev = 1;
            if (i-K >= 0) {
                assert(S[i-K] != need);
                if (i-K-1 >= 0) {
                    prev = sub(total_ways[i-K-1], totalW[i-K-1]);
                }
            }
            ways[i] = add(ways[i], prev);
            totalW[i] = add(totalW[i], prev);
        }

        if (need == 'B') {
            assert(ways[i] == totalW[i]);
        }
    }
}
int main() {
    scanf("%d %d", &N, &K);
    scanf("%s", S);
    calc('B', waysB);
    reverse(S, S+N);
    calc('W', waysW);

    long long sol = 0;
    for (int i=K-1; i+K<N; ++i) {
        sol = (sol + (long long)waysB[i]*waysW[N-i-2])%mod;
    }
    printf("%d\n", int(sol));
    return 0;
}


#include <cassert>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int N, K;
const int MAXN = 1000000;
char S[MAXN+1];
const int mod = 1000000007;
int waysB[MAXN], waysW[MAXN], totalW[MAXN];
int total_ways[MAXN];
int cntA[MAXN+1], cntB[MAXN+1];
int add(int a, int b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
    return a;
}
int sub(int a, int b) {
    a -= b;
    if (a < 0) {
        a += mod;
    }
    return a;
}
void calc(char need, int *ways) {
    for (int i=0; i<N; ++i) {
        cntA[i+1] = cntA[i];
        cntB[i+1] = cntB[i];
        if (S[i] == need) {
            ++cntA[i+1];
        } else if (S[i] != 'X') {
            ++cntB[i+1];
        }
    }
    for (int i=0; i+1<K; ++i) {
        total_ways[i] = i>0 ? total_ways[i-1] : 1;
        if (S[i] == 'X') {
            total_ways[i] = add(total_ways[i], total_ways[i]);
        }
        ways[i] = 0;
    }
    for (int i=K-1; i<N; ++i) {
        total_ways[i] = i>0 ? total_ways[i-1] : 1;
        if (S[i] == 'X') {
            total_ways[i] = add(total_ways[i], total_ways[i]);
        }

        ways[i] = i>0 ? ways[i-1] : 1;
        if (S[i] == 'X') {
            ways[i] = add(ways[i], ways[i]);
        }
        totalW[i] = ways[i];
        if (need == 'W') {
            ways[i] = 0; // for 'W' compute only the ways to end exactly on K Ws
        }

        if (i-K>=0 && S[i-K]==need) continue;
        int other = cntB[i+1] - cntB[i-K+1];
        if (other == 0) {
            int prev = 1;
            if (i-K >= 0) {
                assert(S[i-K] != need);
                if (i-K-1 >= 0) {
                    prev = sub(total_ways[i-K-1], totalW[i-K-1]);
                }
            }
            ways[i] = add(ways[i], prev);
            totalW[i] = add(totalW[i], prev);
        }

        if (need == 'B') {
            assert(ways[i] == totalW[i]);
        }
    }
}
int main() {
    scanf("%d %d", &N, &K);
    scanf("%s", S);
    calc('B', waysB);
    reverse(S, S+N);
    calc('W', waysW);

    long long sol = 0;
    for (int i=K-1; i+K<N; ++i) {
        sol = (sol + (long long)waysB[i]*waysW[N-i-2])%mod;
    }
    printf("%d\n", int(sol));
    return 0;
}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 1000111

char s[NN];

INT lft[NN], rgt[NN];

int cntx[NN], cntw[NN], cntb[NN];

int lsum[NN], rsum[NN];

int sum[NN];

int pw2[NN];

int calc_b(int st, int ed) {

	return cntb[ed] - cntb[st-1];

}

int calc_w(int st, int ed) {

	return cntw[ed] - cntw[st-1];

}

int calc_x(int st, int ed) {

	return cntx[ed] - cntx[st-1];

}

#define rev(a) power((a), MOD-2, MOD)

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, k;

	gn(n, k);

	scanf("%s", s+1);

	INT ans=0;

	for(int i=1; i<=n; i++) {

		cntb[i] = cntb[i-1];

		cntx[i] = cntx[i-1];

		cntw[i] = cntw[i-1];

		if(s[i] == 'X') cntx[i] = cntx[i-1] + 1;

		if(s[i] == 'W') cntw[i] = cntw[i-1] + 1;

		if(s[i] == 'B') cntb[i] = cntb[i-1] + 1;

	}

	pw2[0] = 1;

	for(int i=1; i<=n; i++) {

		pw2[i] = pw2[i-1] * 2 % MOD;

	}

	for(int i=k; i<=n; i++) {

		if(calc_b(i-k+1, i) + calc_x(i-k+1, i) == k and s[i-k]!='B') {

			if(i==k) lft[i] = 1;

			else lft[i] = ((INT)pw2[calc_x(1, i-k-1)] - (INT)lsum[i-k-1] * pw2[calc_x(1, i-k-1)] % MOD+ MOD)%MOD;

		}

		lsum[i] = (lsum[i-1] + (INT)lft[i] * rev(pw2[calc_x(1, i)]) % MOD) % MOD;

	}

	for(int i=n-k+1; i>=1; i--) {

		if(calc_w(i, i+k-1) + calc_x(i, i+k-1) == k and s[i+k]!='W') {

			if(i==n-k+1) rgt[i] = 1;

			else rgt[i] = ((INT)pw2[calc_x(i+k+1, n)] - (INT)rsum[i+k+1] * pw2[calc_x(i+k+1, n)] % MOD + MOD) % MOD;

		}

		rsum[i] = (rsum[i+1] + (INT)rgt[i] * rev(pw2[calc_x(i, n)]) % MOD) % MOD;

		//print(i, rgt[i]);

	}

	for(int i=k; i<=n; i++) {

		ans += (INT)lft[i] * rsum[i+1] % MOD * pw2[calc_x(i+1, n)] % MOD;

		ans %= MOD;

	}

	cout << ans << endl;

	return 0;

}


#include<cstdio>
#include<cstring>
#include<iostream>

#define nn 1000010
#define Mod 1000000007
using namespace std;

char str[nn];
int f1[nn],f2[nn],g1[nn],g2[nn];
int n,m,sm[nn],pw[nn],ans,A[nn],a[nn],b[nn][3];

inline void Add(int &a,int b) {a+=b;if(a>=Mod)a-=Mod;}
inline bool Pd(int l,int r,int op) {return(b[r][3-op]-b[l-1][3-op]==0);}

inline void Work(int *f,int op){
	memset(sm,0,sizeof(sm));
	sm[0]=f[0]=1;
	for (int j=0,i=1;i<=n;i++){
		if (A[i]!=op){
			int nm=sm[i-1];
			if (i-m-1>j-1&&i-m>=1) Add(nm,Mod-sm[i-m-1]);
			else if(j-1>=0)Add(nm,Mod-sm[j-1]);
			f[i]=nm;
		}
		if (A[i]==3-op) j=i;
		sm[i]=sm[i-1],Add(sm[i],f[i]);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	if (m+m>n) {puts("0");return(0);}

	scanf("%s",str+1);
	for (int i=1;i<=n;i++){
		if (str[i]=='X') a[i]=0;
		if (str[i]=='B') a[i]=1;
		if (str[i]=='W') a[i]=2;
	}

	pw[0]=1;
	for (int i=1;i<=n;i++) pw[i]=pw[i-1]*2ll%Mod;
	for (int i=1;i<=n;i++) sm[i]=sm[i-1]+(a[i]>0);
	for (int i=1;i<=n;i++) b[i][a[i]]++;
	for (int i=1;i<=n;i++) b[i][1]+=b[i-1][1],b[i][2]+=b[i-1][2];

	for (int i=1;i<=n;i++) A[i]=a[i];
	Work(f1,1);
	for (int i=1;i<=n;i++) A[n-i+1]=a[i];
	Work(f2,2);
	for (int i=0;i+i<=n;i++) swap(f2[i],f2[n-i+1]);

	for (int i=1;i<=n;i++){
		g1[i]=g1[i-1];
		if (a[i]==0) Add(g1[i],g1[i-1]);
		if (i>=m&&Pd(i-m+1,i,1)) Add(g1[i],f1[i-m]);
	}
	for (int i=m;i+m<=n;i++)if(Pd(i+1,i+m,2)){
		int nm=g1[i]*1ll*f2[i+m+1]%Mod;
		Add(ans,nm);
	}
	printf("%d\n",ans);
}


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>

using namespace std;

const int maxn = 210000;

int n, atop,
    card[maxn+1][2],
    a[maxn+1];
int now[maxn+1][2];
int result=-1;

void init()
{
    int i,j;
    scanf("%d",&n);
    atop=0;
    for (i=1; i<=n; ++i)
    {
        scanf("%d%d",&card[i][0],&card[i][1]);
        a[++atop]=card[i][0];
        a[++atop]=card[i][1];
    }
    sort(a+1,a+atop+1);
    atop=unique(a+1,a+atop+1)-(a+1);

    for (i=1; i<=n; ++i)
    {
        card[i][0]=lower_bound(a+1,a+atop+1,card[i][0])-a;
        card[i][1]=lower_bound(a+1,a+atop+1,card[i][1])-a;
    }
}

void work()
{
    int atleast=(n+1)/2;
    int i,j;
    for (i=1; i<=atop; ++i)
        now[i][0]=now[i][1]=0;
    for (i=1; i<=n; ++i)
    {
        ++now[card[i][0]][0];
        if (card[i][0]!=card[i][1])
            ++now[card[i][1]][1];
    }
    for (i=1; i<=atop; ++i)
        if (now[i][0]+now[i][1]>=atleast)
        {
            if (now[i][0]>=atleast)
                result=0;
            else if ((result==-1)||(atleast-now[i][0]<result))
                result=atleast-now[i][0];
        }
}

void output()
{
    printf("%d\n",result);
}

int main()
{
    //freopen("D.in","r",stdin);
    init();
    work();
    output();
    return 0;
}


#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

const int bigp=1000000007;
const int maxn=1000005;

string s;
int n,k,e,ans,a[maxn],sum[maxn],bsum[maxn],wsum[maxn],t[maxn];
int b1[maxn],w1[maxn],sum1[maxn],b2[maxn],w2[maxn],sum2[maxn];

int mpow(int a,int b)
{
	if (b==0) return 1;
	int c=mpow(a,b/2);
	c=(long long)c*c%bigp;
	if (b%2==1) c=(long long)c*a%bigp;
	return c;
}

int main()
{
	//freopen("D.in","r",stdin);
	cin>>n>>k;
	cin>>s;
	memset(a,0,sizeof(a));
	memset(sum,0,sizeof(sum));
	memset(bsum,0,sizeof(bsum));
	memset(wsum,0,sizeof(wsum));
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='X') a[i]=0; else
		if (s[i-1]=='B') a[i]=1; else
		a[i]=2;
	}
	if (k==1)
	{
		cout<<mpow(2,sum[n])<<endl;
		return 0;
	}
	for (int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1];if (a[i]==0) ++sum[i];
		bsum[i]=bsum[i-1];if (a[i]==1) ++bsum[i];
		wsum[i]=wsum[i-1];if (a[i]==2) ++wsum[i];
	}
	memset(b1,0,sizeof(b1));
	memset(w1,0,sizeof(w1));
	b1[0]=0;
	w1[0]=1;
	sum1[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)
		{
			b1[i]=sum1[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			w1[i]=0;
		}
		else
			if (a[i]==2)
			{
				b1[i]=0;w1[i]=(b1[i-1]+w1[i-1])%bigp;
			}
			else
			{
				w1[i]=(b1[i-1]+w1[i-1])%bigp;
				b1[i]=sum1[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			}
		sum1[i]=(sum1[i-1]+w1[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<w1[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(b2,0,sizeof(b2));
	memset(w2,0,sizeof(w2));
	b2[0]=1;
	w2[0]=0;
	sum2[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==2)
		{
			w2[i]=sum2[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) w2[i]=(w2[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			b2[i]=0;
		}
		else
			if (a[i]==1)
			{
				w2[i]=0;b2[i]=(b2[i-1]+w2[i-1])%bigp;
			}
			else
			{
				b2[i]=(b2[i-1]+w2[i-1])%bigp;
				w2[i]=sum2[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			}
		sum2[i]=(sum2[i-1]+b2[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<b2[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(t,0,sizeof(t));
	for (int i=n-k+1;i>=1;i--)
	{
		if (a[i]==0) t[i]=t[i+1]*2%bigp; else t[i]=t[i+1];
		if (bsum[i+k-1]-bsum[i-1]==0) t[i]=(t[i]+b2[n+1-i-k])%bigp;
	}
	ans=0;
	for (int i=k;i<n;i++)
		if (wsum[i]-wsum[i-k]==0)
			ans=((long long)ans+(long long)w1[i-k]*t[i+1])%bigp;
	cout<<ans<<endl;

	return 0;
}


#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

const int bigp=1000000007;
const int maxn=1000005;

string s;
int n,k,e,ans,a[maxn],sum[maxn],bsum[maxn],wsum[maxn],t[maxn];
int b1[maxn],w1[maxn],sum1[maxn],b2[maxn],w2[maxn],sum2[maxn];

int mpow(int a,int b)
{
	if (b==0) return 1;
	int c=mpow(a,b/2);
	c=(long long)c*c%bigp;
	if (b%2==1) c=(long long)c*a%bigp;
	return c;
}

int main()
{
	freopen("D.in","r",stdin);
	cin>>n>>k;
	cin>>s;
	memset(a,0,sizeof(a));
	memset(sum,0,sizeof(sum));
	memset(bsum,0,sizeof(bsum));
	memset(wsum,0,sizeof(wsum));
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='X') a[i]=0; else
		if (s[i-1]=='B') a[i]=1; else
		a[i]=2;
	}
	if (k==1)
	{
		cout<<mpow(2,sum[n])<<endl;
		return 0;
	}
	for (int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1];if (a[i]==0) ++sum[i];
		bsum[i]=bsum[i-1];if (a[i]==1) ++bsum[i];
		wsum[i]=wsum[i-1];if (a[i]==2) ++wsum[i];
	}
	memset(b1,0,sizeof(b1));
	memset(w1,0,sizeof(w1));
	b1[0]=0;
	w1[0]=1;
	sum1[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)
		{
			b1[i]=sum1[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			w1[i]=0;
		}
		else
			if (a[i]==2)
			{
				b1[i]=0;w1[i]=(b1[i-1]+w1[i-1])%bigp;
			}
			else
			{
				w1[i]=(b1[i-1]+w1[i-1])%bigp;
				b1[i]=sum1[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			}
		sum1[i]=(sum1[i-1]+w1[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<w1[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(b2,0,sizeof(b2));
	memset(w2,0,sizeof(w2));
	b2[0]=1;
	w2[0]=0;
	sum2[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==2)
		{
			w2[i]=sum2[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) w2[i]=(w2[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			b2[i]=0;
		}
		else
			if (a[i]==1)
			{
				w2[i]=0;b2[i]=(b2[i-1]+w2[i-1])%bigp;
			}
			else
			{
				b2[i]=(b2[i-1]+w2[i-1])%bigp;
				w2[i]=sum2[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			}
		sum2[i]=(sum2[i-1]+b2[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<b2[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(t,0,sizeof(t));
	for (int i=n-k+1;i>=1;i--)
	{
		if (a[i]==0) t[i]=t[i+1]*2%bigp; else t[i]=t[i+1];
		if (bsum[i+k-1]-bsum[i-1]==0) t[i]=(t[i]+b2[n+1-i-k])%bigp;
	}
	ans=0;
	for (int i=k;i<n;i++)
		if (wsum[i]-wsum[i-k]==0)
			ans=((long long)ans+(long long)w1[i-k]*t[i+1])%bigp;
	cout<<ans<<endl;

	return 0;
}


#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

const int bigp=1000000007;
const int maxn=1000005;

string s;
int n,k,e,ans,a[maxn],sum[maxn],bsum[maxn],wsum[maxn],t[maxn];
int b1[maxn],w1[maxn],sum1[maxn],b2[maxn],w2[maxn],sum2[maxn];

int mpow(int a,int b)
{
	if (b==0) return 1;
	int c=mpow(a,b/2);
	c=(long long)c*c%bigp;
	if (b%2==1) c=(long long)c*a%bigp;
	return c;
}

int main()
{
	//freopen("D.in","r",stdin);
	cin>>n>>k;
	cin>>s;
	memset(a,0,sizeof(a));
	memset(sum,0,sizeof(sum));
	memset(bsum,0,sizeof(bsum));
	memset(wsum,0,sizeof(wsum));
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='X') a[i]=0; else
		if (s[i-1]=='B') a[i]=1; else
		a[i]=2;
	}
	for (int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1];if (a[i]==0) ++sum[i];
		bsum[i]=bsum[i-1];if (a[i]==1) ++bsum[i];
		wsum[i]=wsum[i-1];if (a[i]==2) ++wsum[i];
	}
	memset(b1,0,sizeof(b1));
	memset(w1,0,sizeof(w1));
	b1[0]=0;
	w1[0]=1;
	sum1[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)
		{
			b1[i]=sum1[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			w1[i]=0;
		}
		else
			if (a[i]==2)
			{
				b1[i]=0;w1[i]=(b1[i-1]+w1[i-1])%bigp;
			}
			else
			{
				w1[i]=(b1[i-1]+w1[i-1])%bigp;
				b1[i]=sum1[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			}
		sum1[i]=(sum1[i-1]+w1[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<w1[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(b2,0,sizeof(b2));
	memset(w2,0,sizeof(w2));
	b2[0]=1;
	w2[0]=0;
	sum2[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==2)
		{
			w2[i]=sum2[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) w2[i]=(w2[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			b2[i]=0;
		}
		else
			if (a[i]==1)
			{
				w2[i]=0;b2[i]=(b2[i-1]+w2[i-1])%bigp;
			}
			else
			{
				b2[i]=(b2[i-1]+w2[i-1])%bigp;
				w2[i]=sum2[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			}
		sum2[i]=(sum2[i-1]+b2[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<b2[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(t,0,sizeof(t));
	for (int i=n-k+1;i>=1;i--)
	{
		if (a[i]==0) t[i]=t[i+1]*2%bigp; else t[i]=t[i+1];
		if (bsum[i+k-1]-bsum[i-1]==0) t[i]=(t[i]+b2[n+1-i-k])%bigp;
	}
	ans=0;
	for (int i=k;i<n;i++)
		if (wsum[i]-wsum[i-k]==0)
			ans=((long long)ans+(long long)w1[i-k]*t[i+1])%bigp;
	cout<<ans<<endl;

	return 0;
}


#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

const int bigp=1000000007;
const int maxn=1000005;

string s;
int n,k,e,ans,a[maxn],sum[maxn],bsum[maxn],wsum[maxn],t[maxn];
int b1[maxn],w1[maxn],sum1[maxn],b2[maxn],w2[maxn],sum2[maxn];

int mpow(int a,int b)
{
	if (b==0) return 1;
	int c=mpow(a,b/2);
	c=(long long)c*c%bigp;
	if (b%2==1) c=(long long)c*a%bigp;
	return c;
}

int main()
{
	//freopen("D.in","r",stdin);
	cin>>n>>k;
	cin>>s;
	memset(a,0,sizeof(a));
	memset(sum,0,sizeof(sum));
	memset(bsum,0,sizeof(bsum));
	memset(wsum,0,sizeof(wsum));
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='X') a[i]=0; else
		if (s[i-1]=='B') a[i]=1; else
		a[i]=2;
	}
	for (int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1];if (a[i]==0) ++sum[i];
		bsum[i]=bsum[i-1];if (a[i]==1) ++bsum[i];
		wsum[i]=wsum[i-1];if (a[i]==2) ++wsum[i];
	}
	memset(b1,0,sizeof(b1));
	memset(w1,0,sizeof(w1));
	b1[0]=0;
	w1[0]=1;
	sum1[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)
		{
			b1[i]=sum1[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			w1[i]=0;
		}
		else
			if (a[i]==2)
			{
				b1[i]=0;w1[i]=(b1[i-1]+w1[i-1])%bigp;
				if (k==1) w1[i]=w1[i-1];
			}
			else
			{
				w1[i]=(b1[i-1]+w1[i-1])%bigp;
				if (k==1) w1[i]=w1[i-1];
				b1[i]=sum1[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			}
		sum1[i]=(sum1[i-1]+w1[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<w1[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(b2,0,sizeof(b2));
	memset(w2,0,sizeof(w2));
	b2[0]=1;
	w2[0]=0;
	sum2[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==2)
		{
			w2[i]=sum2[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			b2[i]=0;
		}
		else
			if (a[i]==1)
			{
				w2[i]=0;b2[i]=(b2[i-1]+w2[i-1])%bigp;
				if (k==1) b2[i]=b2[i-1];
			}
			else
			{
				b2[i]=(b2[i-1]+w2[i-1])%bigp;
				if (k==1) b2[i]=b2[i-1];
				w2[i]=sum2[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			}
		sum2[i]=(sum2[i-1]+b2[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<b2[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(t,0,sizeof(t));
	for (int i=n-k+1;i>=1;i--)
	{
		if (a[i]==0) t[i]=t[i+1]*2%bigp; else t[i]=t[i+1];
		if (bsum[i+k-1]-bsum[i-1]==0) t[i]=(t[i]+b2[n+1-i-k])%bigp;
	}
	ans=0;
	for (int i=k;i<=n;i++)
		if (wsum[i]-wsum[i-k]==0)
			ans=((long long)ans+(long long)w1[i-k]*t[i+1])%bigp;
	cout<<ans<<endl;

	return 0;
}


#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

const int bigp=1000000007;
const int maxn=1000005;

string s;
int n,k,e,ans,a[maxn],sum[maxn],bsum[maxn],wsum[maxn],t[maxn];
int b1[maxn],w1[maxn],sum1[maxn],b2[maxn],w2[maxn],sum2[maxn];

int mpow(int a,int b)
{
	if (b==0) return 1;
	int c=mpow(a,b/2);
	c=(long long)c*c%bigp;
	if (b%2==1) c=(long long)c*a%bigp;
	return c;
}

int main()
{
	//freopen("D.in","r",stdin);
	cin>>n>>k;
	cin>>s;
	memset(a,0,sizeof(a));
	memset(sum,0,sizeof(sum));
	memset(bsum,0,sizeof(bsum));
	memset(wsum,0,sizeof(wsum));
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='X') a[i]=0; else
		if (s[i-1]=='B') a[i]=1; else
		a[i]=2;
	}
	for (int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1];if (a[i]==0) ++sum[i];
		bsum[i]=bsum[i-1];if (a[i]==1) ++bsum[i];
		wsum[i]=wsum[i-1];if (a[i]==2) ++wsum[i];
	}
	memset(b1,0,sizeof(b1));
	memset(w1,0,sizeof(w1));
	b1[0]=0;
	w1[0]=1;
	sum1[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)
		{
			b1[i]=sum1[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			w1[i]=0;
		}
		else
			if (a[i]==2)
			{
				b1[i]=0;w1[i]=(b1[i-1]+w1[i-1])%bigp;
				if (k==1) w1[i]=w1[i-1];
			}
			else
			{
				w1[i]=(b1[i-1]+w1[i-1])%bigp;
				if (k==1) w1[i]=w1[i-1];
				b1[i]=sum1[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			}
		sum1[i]=(sum1[i-1]+w1[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<w1[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(b2,0,sizeof(b2));
	memset(w2,0,sizeof(w2));
	b2[0]=1;
	w2[0]=0;
	sum2[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==2)
		{
			w2[i]=sum2[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) w2[i]=(w2[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			b2[i]=0;
		}
		else
			if (a[i]==1)
			{
				w2[i]=0;b2[i]=(b2[i-1]+w2[i-1])%bigp;
				if (k==1) b2[i]=b2[i-1];
			}
			else
			{
				b2[i]=(b2[i-1]+w2[i-1])%bigp;
				if (k==1) b2[i]=b2[i-1];
				w2[i]=sum2[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			}
		sum2[i]=(sum2[i-1]+b2[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<b2[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(t,0,sizeof(t));
	for (int i=n-k+1;i>=1;i--)
	{
		if (a[i]==0) t[i]=t[i+1]*2%bigp; else t[i]=t[i+1];
		if (bsum[i+k-1]-bsum[i-1]==0) t[i]=(t[i]+b2[n+1-i-k])%bigp;
	}
	ans=0;
	for (int i=k;i<=n;i++)
		if (wsum[i]-wsum[i-k]==0)
			ans=((long long)ans+(long long)w1[i-k]*t[i+1])%bigp;
	cout<<ans<<endl;

	return 0;
}


#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

const int bigp=1000000007;
const int maxn=1000005;

string s;
int n,k,e,ans,a[maxn],sum[maxn],bsum[maxn],wsum[maxn],t[maxn];
int b1[maxn],w1[maxn],sum1[maxn],b2[maxn],w2[maxn],sum2[maxn];

int mpow(int a,int b)
{
	if (b==0) return 1;
	int c=mpow(a,b/2);
	c=(long long)c*c%bigp;
	if (b%2==1) c=(long long)c*a%bigp;
	return c;
}

int main()
{
	//freopen("D.in","r",stdin);
	cin>>n>>k;
	cin>>s;
	memset(a,0,sizeof(a));
	memset(sum,0,sizeof(sum));
	memset(bsum,0,sizeof(bsum));
	memset(wsum,0,sizeof(wsum));
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='X') a[i]=0; else
		if (s[i-1]=='B') a[i]=1; else
		a[i]=2;
	}
	for (int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1];if (a[i]==0) ++sum[i];
		bsum[i]=bsum[i-1];if (a[i]==1) ++bsum[i];
		wsum[i]=wsum[i-1];if (a[i]==2) ++wsum[i];
	}
	if (k==1)
	{
		cout<<mpow(2,sum[n])<<endl;
		return 0;
	}
	memset(b1,0,sizeof(b1));
	memset(w1,0,sizeof(w1));
	b1[0]=0;
	w1[0]=1;
	sum1[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)
		{
			b1[i]=sum1[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			w1[i]=0;
		}
		else
			if (a[i]==2)
			{
				b1[i]=0;w1[i]=(b1[i-1]+w1[i-1])%bigp;
			}
			else
			{
				w1[i]=(b1[i-1]+w1[i-1])%bigp;
				b1[i]=sum1[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			}
		sum1[i]=(sum1[i-1]+w1[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<w1[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(b2,0,sizeof(b2));
	memset(w2,0,sizeof(w2));
	b2[0]=1;
	w2[0]=0;
	sum2[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==2)
		{
			w2[i]=sum2[i-1];
			int e2=max(i-k+1,0);
			if (e2>0) w2[i]=(w2[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			b2[i]=0;
		}
		else
			if (a[i]==1)
			{
				w2[i]=0;b2[i]=(b2[i-1]+w2[i-1])%bigp;
			}
			else
			{
				b2[i]=(b2[i-1]+w2[i-1])%bigp;
				w2[i]=sum2[i-1];
				int e2=max(i-k+1,0);
				if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			}
		sum2[i]=(sum2[i-1]+b2[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<b2[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(t,0,sizeof(t));
	for (int i=n-k+1;i>=1;i--)
	{
		if (a[i]==0) t[i]=t[i+1]*2%bigp; else t[i]=t[i+1];
		if (bsum[i+k-1]-bsum[i-1]==0) t[i]=(t[i]+b2[n+1-i-k])%bigp;
	}
	ans=0;
	for (int i=k;i<n;i++)
		if (wsum[i]-wsum[i-k]==0)
			ans=((long long)ans+(long long)w1[i-k]*t[i+1])%bigp;
	cout<<ans<<endl;

	return 0;
}


#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

const int bigp=1000000007;
const int maxn=1000005;

string s;
int n,k,e,ans,a[maxn],sum[maxn],bsum[maxn],wsum[maxn],t[maxn];
int b1[maxn],w1[maxn],sum1[maxn],b2[maxn],w2[maxn],sum2[maxn],cb[maxn],cw[maxn];

int mpow(int a,int b)
{
	if (b==0) return 1;
	int c=mpow(a,b/2);
	c=(long long)c*c%bigp;
	if (b%2==1) c=(long long)c*a%bigp;
	return c;
}

int main()
{
	//freopen("D.in","r",stdin);
	cin>>n>>k;
	cin>>s;
	memset(a,0,sizeof(a));
	memset(sum,0,sizeof(sum));
	memset(bsum,0,sizeof(bsum));
	memset(wsum,0,sizeof(wsum));
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='X') a[i]=0; else
		if (s[i-1]=='B') a[i]=1; else
		a[i]=2;
	}
	for (int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1];if (a[i]==0) ++sum[i];
		bsum[i]=bsum[i-1];if (a[i]==1) ++bsum[i];
		wsum[i]=wsum[i-1];if (a[i]==2) ++wsum[i];
	}
	cw[0]=-1;
	for (int i=1;i<=n;i++)
	{
		cw[i]=cw[i-1];
		if (a[i]==2) cw[i]=i;
	}
	memset(b1,0,sizeof(b1));
	memset(w1,0,sizeof(w1));
	b1[0]=0;
	w1[0]=1;
	sum1[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)
		{
			b1[i]=sum1[i-1];
			int e2=max(max(i-k+1,0),cw[i]);
			if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			//for (int j=i-1;j>=max(i-k+1,0);j--) b1[i]=(b1[i]+w1[j])%bigp;
			w1[i]=0;
		}
		else
			if (a[i]==2)
			{
				b1[i]=0;w1[i]=(b1[i-1]+w1[i-1])%bigp;
				if (k==1) w1[i]=w1[i-1];
			}
			else
			{
				w1[i]=(b1[i-1]+w1[i-1])%bigp;
				if (k==1) w1[i]=w1[i-1];
				b1[i]=sum1[i-1];
				int e2=max(max(i-k+1,0),cw[i]);
				if (e2>0) b1[i]=(b1[i]-sum1[e2-1]+bigp)%bigp;
			}
		sum1[i]=(sum1[i-1]+w1[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<w1[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	cb[0]=-1;
	for (int i=1;i<=n;i++)
	{
		cb[i]=cb[i-1];
		if (a[i]==1) cb[i]=i;
	}
	memset(b2,0,sizeof(b2));
	memset(w2,0,sizeof(w2));
	b2[0]=1;
	w2[0]=0;
	sum2[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==2)
		{
			w2[i]=sum2[i-1];
			int e2=max(max(i-k+1,0),cb[i]);
			if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			b2[i]=0;
		}
		else
			if (a[i]==1)
			{
				w2[i]=0;b2[i]=(b2[i-1]+w2[i-1])%bigp;
				if (k==1) b2[i]=b2[i-1];
			}
			else
			{
				b2[i]=(b2[i-1]+w2[i-1])%bigp;
				if (k==1) b2[i]=b2[i-1];
				w2[i]=sum2[i-1];
				int e2=max(max(i-k+1,0),cb[i]);
				if (e2>0) w2[i]=(w2[i]-sum2[e2-1]+bigp)%bigp;
			}
		sum2[i]=(sum2[i-1]+b2[i])%bigp;
	}
	//for (int i=1;i<=n;i++) cout<<b2[i]<<" "<<w2[i]<<endl;
	for (int i=1;i<=n/2;i++) swap(a[i],a[n+1-i]);
	memset(t,0,sizeof(t));
	for (int i=n-k+1;i>=1;i--)
	{
		if (a[i]==0) t[i]=t[i+1]*2%bigp; else t[i]=t[i+1];
		if (bsum[i+k-1]-bsum[i-1]==0) t[i]=(t[i]+b2[n+1-i-k])%bigp;
		//cout<<i<<" "<<t[i]<<endl;
	}
	ans=0;
	for (int i=k;i<=n;i++)
		if (wsum[i]-wsum[i-k]==0)
			ans=((long long)ans+(long long)w1[i-k]*t[i+1])%bigp;
	cout<<ans<<endl;

	return 0;
}


#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#define pb push_back
#define MOD 1000000007
using namespace std;
#define SIZE 1000100
long long two[SIZE],wb[3][SIZE],bb[SIZE],ww[SIZE],rr[SIZE];
char s[SIZE];
int get(char c,int ll,int rr){
    if(c=='W')return wb[0][rr]-wb[0][ll-1];
    else if(c=='B')return wb[1][rr]-wb[1][ll-1];
    else return wb[2][rr]-wb[2][ll-1];
}
int main(){
    int i,j,k,n;
    long long an=0;
    cin>>n>>k;
    two[0]=1;
    for(i=1;i<SIZE;i++)two[i]=two[i-1]*2%MOD;
    if(k*2>n){
        puts("0");
        return 0;
    }
    scanf("%s",s+1);
    for(i=1;i<=n;i++){
        wb[0][i]=wb[0][i-1]+(s[i]=='W');
        wb[1][i]=wb[1][i-1]+(s[i]=='B');
        wb[2][i]=wb[2][i-1]+(s[i]=='X');
    }
    long long cal=0;
    for(i=1;i<=n-2*k+1;i++){
        if(get('W',i,i+k-1)==0){
            bb[i]=two[wb[2][i-1]];
            bb[i]-=cal;
            bb[i]-=bb[i-1]-bb[max(i-k,0)];
            bb[i]%=MOD;
            if(bb[i]<0)bb[i]+=MOD;
        }
        if(s[i]=='X')cal=cal*2%MOD;
        bb[i]+=bb[i-1];
        if(i>=k){
            cal+=bb[i-k+1]-bb[i-k];
            cal%=MOD;
        }
    }
    cal=0;
    for(i=k;i<=n-k;i++){
        if(s[i]=='X')cal=cal*2%MOD;
        cal+=bb[i-k+1]-bb[i-k];
        cal%=MOD;
        rr[i]=cal;
    }
    cal=0;
    for(i=n;i>=2*k;i--){
        if(get('B',i-k+1,i)==0){
            ww[i]=two[get('X',i+1,n)];
            ww[i]-=cal;
            ww[i]-=ww[i+1]-ww[min(i+k,n+1)];
            ww[i]%=MOD;
            if(ww[i]<0)ww[i]+=MOD;
        }
        if(s[i]=='X')cal=cal*2%MOD;
        an+=ww[i]*rr[i-k]%MOD;
        an%=MOD;
        ww[i]+=ww[i+1];
        if(i<=n-k+1){
            cal+=ww[i+k-1]-ww[i+k];
            cal%=MOD;
        }
    }
    if(an<0)an+=MOD;
    cout<<an<<endl;
    return 0;
}


#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#define pb push_back
#define MOD 1000000007
using namespace std;
#define SIZE 1000100
long long two[SIZE];
char s[SIZE],wb[3][SIZE],bb[SIZE],ww[SIZE],rr[SIZE];
int get(char c,int ll,int rr){
    if(c=='W')return wb[0][rr]-wb[0][ll-1];
    else if(c=='B')return wb[1][rr]-wb[1][ll-1];
    else return wb[2][rr]-wb[2][ll-1];
}
int main(){
    int i,j,k,n;
    long long an=0;
    cin>>n>>k;
    two[0]=1;
    for(i=1;i<SIZE;i++)two[i]=two[i-1]*2%MOD;
    if(k*2>n){
        puts("0");
        return 0;
    }
    scanf("%s",s+1);
    for(i=1;i<=n;i++){
        wb[0][i]=wb[0][i-1]+(s[i]=='W');
        wb[1][i]=wb[1][i-1]+(s[i]=='B');
        wb[2][i]=wb[2][i-1]+(s[i]=='X');
    }
    long long cal=0;
    for(i=1;i<=n-2*k+1;i++){
        if(get('W',i,i+k-1)==0){
            bb[i]=two[wb[2][i-1]];
            bb[i]-=cal;
            bb[i]-=bb[i-1]-bb[max(i-k,0)];
            bb[i]%=MOD;
            if(bb[i]<0)bb[i]+=MOD;
        }
        if(s[i]=='X')cal=cal*2%MOD;
        bb[i]+=bb[i-1];
        if(i>=k){
            cal+=bb[i-k+1]-bb[i-k];
            cal%=MOD;
        }
    }
    cal=0;
    for(i=k;i<=n-k;i++){
        if(s[i]=='X')cal=cal*2%MOD;
        cal+=bb[i-k+1]-bb[i-k];
        cal%=MOD;
        rr[i]=cal;
    }
    cal=0;
    for(i=n;i>=2*k;i--){
        if(get('B',i-k+1,i)==0){
            ww[i]=two[get('X',i+1,n)];
            ww[i]-=cal;
            ww[i]-=ww[i+1]-ww[min(i+k,n+1)];
            ww[i]%=MOD;
            if(ww[i]<0)ww[i]+=MOD;
        }
        if(s[i]=='X')cal=cal*2%MOD;
        an+=ww[i]*rr[i-k]%MOD;
        an%=MOD;
        ww[i]+=ww[i+1];
        if(i<=n-k+1){
            cal+=ww[i+k-1]-ww[i+k];
            cal%=MOD;
        }
    }
    if(an<0)an+=MOD;
    cout<<an<<endl;
    return 0;
}


#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#define pb push_back
#define MOD 1000000007
using namespace std;
#define SIZE 1000100
long long two[SIZE];
char s[SIZE],wb[3][SIZE],bb[SIZE],ww[SIZE],rr[SIZE];
int get(char c,int ll,int rr){
    if(c=='W')return wb[0][rr]-wb[0][ll-1];
    else if(c=='B')return wb[1][rr]-wb[1][ll-1];
    else return wb[2][rr]-wb[2][ll-1];
}
int main(){
    int i,j,k,n;
    long long an=0;
    cin>>n>>k;
    two[0]=1;
    for(i=1;i<SIZE;i++)two[i]=two[i-1]*2%MOD;
    if(k*2>n){
        puts("0");
        return 0;
    }
    scanf("%s",s+1);
    for(i=1;i<=n;i++){
        wb[0][i]=wb[0][i-1]+(s[i]=='W');
        wb[1][i]=wb[1][i-1]+(s[i]=='B');
        wb[2][i]=wb[2][i-1]+(s[i]=='X');
    }
    long long cal=0;
    for(i=1;i<=n-2*k+1;i++){
        if(get('W',i,i+k-1)==0){
            bb[i]=two[wb[2][i-1]];
            bb[i]-=cal;
            bb[i]-=bb[i-1]-bb[max(i-k,0)];
            bb[i]%=MOD;
            if(bb[i]<0)bb[i]+=MOD;
        }
        if(s[i]=='X')cal=cal*2%MOD;
        if(i>=k){
            cal+=bb[i-k+1]-bb[i-k];
            cal%=MOD;
        }
        bb[i]+=bb[i-1];
    }
    cal=0;
    for(i=k;i<=n-k;i++){
        if(s[i]=='X')cal=cal*2%MOD;
        cal+=bb[i-k+1]-bb[i-k];
        cal%=MOD;
        rr[i]=cal;
    }
    cal=0;
    for(i=n;i>=2*k;i--){
        if(get('B',i-k+1,i)==0){
            ww[i]=two[get('X',i+1,n)];
            ww[i]-=cal;
            ww[i]-=ww[i+1]-ww[min(i+k,n+1)];
            ww[i]%=MOD;
            if(ww[i]<0)ww[i]+=MOD;
        }
        if(s[i]=='X')cal=cal*2%MOD;
        if(i<=n-k+1){
            cal+=ww[i+k-1]-ww[i+k];
            cal%=MOD;
        }
        an+=ww[i]*rr[i-k]%MOD;
        an%=MOD;
        ww[i]+=ww[i+1];
    }
    if(an<0)an+=MOD;
    cout<<an<<endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#define MOD 1000000007LL
#define N 100100

using namespace std;
typedef long long ll;

ll pd[N];
ll pd2[N];
ll pd3[N];
ll pd4[N];
char s[N];

int main(){
    int n, k, u;
    scanf("%d %d %s",&n,&k,s+1);

    ll tmp = 1LL;
    pd[0] = 1LL;
    u = 0;
    for(int i=1; i<=n; i++){
        if(i-k-1 >= u) tmp = (tmp-pd[i-k-1]+MOD)%MOD, u=i-k;
        if(s[i] == 'B') pd[i] = 0;
        else pd[i] = tmp;
        if(s[i] == 'W') tmp = 0, u=i;
        tmp = (tmp+pd[i])%MOD;
    }

    int p=-1;
    pd2[0]=0;
    for(int i=1; i<=n; i++){
        if(s[i] == 'W') p = i;
        if(i < k) pd2[i] = 0;
        else if(i == k) pd2[i] = (p == -1) ? 1 : 0;
        else pd2[i] = (p <= i-k) ? pd[i-k] : 0;
        //printf(" %lld",pd2[i]);
    }
    //printf("\n");

    tmp = 0;
    pd3[0] = 0;
    u = 0;
    for(int i=1; i<=n; i++){
        if(i-k-1 >= u) tmp = (tmp-pd3[i-k-1]+MOD)%MOD, u = i-k;
        if(s[i] == 'W') pd3[i] = 0;
        else pd3[i] = (tmp+pd2[i])%MOD;

        if(s[i] == 'B') tmp = 0, u = i;
        tmp = (tmp+pd3[i])%MOD;
        //printf(" %lld",pd3[i]);
    }
    //printf("\n");

    p=-1;
    for(int i=1; i<=n; i++){
        if(s[i] == 'B') p = i;
        if(i < k) pd4[i] = 0;
        else pd4[i] = (p <= i-k) ? pd3[i-k] : 0;
        //printf(" %lld",pd4[i]);
    }
    //printf("\n");

    ll aux = 1LL;
    ll rsp=0;
    for(int i=n; i>=1; i--){
        rsp = (rsp + (pd4[i]*aux)%MOD)%MOD;
        if(s[i] == 'X') aux = (aux*2LL)%MOD;
    }

    cout << rsp << endl;

    return 0;
}


#include <cstdio>
#include <iostream>
#define MOD 1000000007LL
#define N 1001000

using namespace std;
typedef long long ll;

ll pd[N];
ll pd2[N];
ll pd3[N];
ll pd4[N];
char s[N];

int main(){
    int n, k, u;
    scanf("%d %d %s",&n,&k,s+1);

    ll tmp = 1LL;
    pd[0] = 1LL;
    u = 0;
    for(int i=1; i<=n; i++){
        if(i-k-1 >= u) tmp = (tmp-pd[i-k-1]+MOD)%MOD, u=i-k;
        if(s[i] == 'B') pd[i] = 0;
        else pd[i] = tmp;
        if(s[i] == 'W') tmp = 0, u=i;
        tmp = (tmp+pd[i])%MOD;
    }

    int p=-1;
    pd2[0]=0;
    for(int i=1; i<=n; i++){
        if(s[i] == 'W') p = i;
        if(i < k) pd2[i] = 0;
        else if(i == k) pd2[i] = (p == -1) ? 1 : 0;
        else pd2[i] = (p <= i-k) ? pd[i-k] : 0;
        //printf(" %lld",pd2[i]);
    }
    //printf("\n");

    tmp = 0;
    pd3[0] = 0;
    u = 0;
    for(int i=1; i<=n; i++){
        if(i-k-1 >= u) tmp = (tmp-pd3[i-k-1]+MOD)%MOD, u = i-k;
        if(s[i] == 'W') pd3[i] = 0;
        else pd3[i] = (tmp+pd2[i])%MOD;

        if(s[i] == 'B') tmp = 0, u = i;
        tmp = (tmp+pd3[i])%MOD;
        //printf(" %lld",pd3[i]);
    }
    //printf("\n");

    p=-1;
    for(int i=1; i<=n; i++){
        if(s[i] == 'B') p = i;
        if(i < k) pd4[i] = 0;
        else pd4[i] = (p <= i-k) ? pd3[i-k] : 0;
        //printf(" %lld",pd4[i]);
    }
    //printf("\n");

    ll aux = 1LL;
    ll rsp=0;
    for(int i=n; i>=1; i--){
        rsp = (rsp + (pd4[i]*aux)%MOD)%MOD;
        if(s[i] == 'X') aux = (aux*2LL)%MOD;
    }

    cout << rsp << endl;

    return 0;
}


#include <cstdio>

typedef long long ll;

const int MOD=1000000007;
const int MAXN=1000006;

char in[MAXN];
int n, k;
int B[MAXN], W[MAXN], L[MAXN], P[MAXN], A[MAXN];

int ileB(int x, int y) {return (y>=x) ? B[y]-B[x-1] : 0;}
int ileW(int x, int y) {return (y>=x) ? W[y]-W[x-1] : 0;}

int LB(int x)
{
  if(ileW(x-k+1,x-1)==0 && in[x-k]!='B') return (L[x-1]-L[x-k-1]+MOD)%MOD;
  return L[x-1];
}

int LW(int x) { return L[x-1];}

int PB(int x) { return P[x+1];}

int PW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (P[x+1]-P[x+k+1]+MOD)%MOD;
  return P[x+1];
}

int AB(int x) { return A[x+1];}

int AW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (A[x+1]+P[x+k+1])%MOD;
  return A[x+1];
}

int main()
{
  scanf("%d %d", &n, &k);
  scanf("%s", in+1);

  for(int i=1; i<=n; i++)
  {
    B[i]=B[i-1], W[i]=W[i-1];
    if(in[i]=='B') B[i]++;
    if(in[i]=='W') W[i]++;
  }

  L[0]=1;
  for(int i=1; i<=n; i++)
    if(i<=k)
    {
      L[i]=L[i-1];
      if(in[i]=='X') L[i]=(2*L[i])%MOD;
      if(i==k && ileW(1,k)==0) L[i]=(L[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') L[i]=LB(i);
      if(in[i]=='W') L[i]=LW(i);
      if(in[i]=='X') L[i]=(LB(i)+LW(i))%MOD;
    }

  P[n+1]=1;
  for(int i=n; i>=1; i--)
    if(i+k-1>=n)
    {
      P[i]=P[i+1];
      if(in[i]=='X') P[i]=(2*P[i])%MOD;
      if(i+k-1==n && ileB(i,n)==0) A[i]=1, P[i]=(P[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') P[i]=PB(i), A[i]=AB(i);
      if(in[i]=='W') P[i]=PW(i), A[i]=AW(i);
      if(in[i]=='X') P[i]=(PB(i)+PW(i))%MOD, A[i]=(AB(i)+AW(i))%MOD;
    }

  ll result=0;
  for(int i=1; i+k-1<=n; i++)
  {
    if(ileW(i,i+k-1)>0) continue;

    if(i==1) result+=ll(L[i-1])*ll(A[i+k]);
    else if(in[i-1]!='B') result+=ll(L[i-2])*ll(A[i+k]);

    result%=MOD;
  }

  printf("%lld\n", result);

  return 0;
}


#include <cstdio>

typedef long long ll;

const int MOD=1000000007;
const int MAXN=1000006;

char in[MAXN];
int n, k;
ll B[MAXN], W[MAXN], L[MAXN], P[MAXN], A[MAXN];

int ileB(int x, int y) {return (y>=x) ? B[y]-B[x-1] : 0;}
int ileW(int x, int y) {return (y>=x) ? W[y]-W[x-1] : 0;}

int LB(int x)
{
  if(ileW(x-k+1,x-1)==0 && in[x-k]!='B') return (L[x-1]-L[x-k-1]+MOD)%MOD;
  return L[x-1];
}

int LW(int x)
{
  return L[x-1];
}

int PB(int x)
{
  return P[x+1];
}

int PW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (P[x+1]-P[x+k+1]+MOD)%MOD;
  return P[x+1];
}

int AB(int x)
{
  return A[x+1];
}

int AW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (A[x+1]+P[x+k+1])%MOD;
  return A[x+1];
}

int main()
{
  scanf("%d %d", &n, &k);
  scanf("%s", in+1);

  for(int i=1; i<=n; i++)
  {
    B[i]=B[i-1], W[i]=W[i-1];
    if(in[i]=='B') B[i]++;
    if(in[i]=='W') W[i]++;
  }

  L[0]=1;
  for(int i=1; i<=n; i++)
    if(i<=k)
    {
      L[i]=L[i-1];
      if(in[i]=='X') L[i]=(2*L[i])%MOD;
      if(i==k && ileW(1,k)==0) L[i]=(L[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') L[i]=LB(i);
      if(in[i]=='W') L[i]=LW(i);
      if(in[i]=='X') L[i]=(LB(i)+LW(i))%MOD;
    }

  P[n+1]=1;
  for(int i=n; i>=1; i--)
    if(i+k-1>n)
    {
      P[i]=P[i+1];
      if(in[i]=='X') P[i]=(2*P[i])%MOD;
    }
    else if(i+k-1==n)
    {
      P[i]=P[i+1];
      if(in[i]=='X') P[i]=(2*P[i])%MOD;
      if(ileB(i,n)==0) A[i]=1, P[i]=(P[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') P[i]=PB(i), A[i]=AB(i);
      if(in[i]=='W') P[i]=PW(i), A[i]=AW(i);
      if(in[i]=='X') P[i]=(PB(i)+PW(i))%MOD, A[i]=(AB(i)+AW(i))%MOD;
    }

  ll result=0;

  for(int i=1; i+k-1<=n; i++)
  {
    if(ileW(i,i+k-1)>0) continue;

    if(i==1) result+=ll(L[i-1])*ll(A[i+k]);
    else if(in[i-1]!='B') result+=ll(L[i-2])*ll(A[i+k]);

    result%=ll(MOD);
  }

  printf("%lld\n", result);

  return 0;
}


#include <cstdio>

typedef long long ll;

const int MOD=1000000007;
const int MAXN=1000006;

char in[MAXN];
int n, k;
ll B[MAXN], W[MAXN], L[MAXN], P[MAXN], A[MAXN];

int ileB(int x, int y) {return (y>=x) ? B[y]-B[x-1] : 0;}
int ileW(int x, int y) {return (y>=x) ? W[y]-W[x-1] : 0;}

int LB(int x)
{
  if(ileW(x-k+1,x-1)==0 && in[x-k]!='B') return (L[x-1]-L[x-k-1]+MOD)%MOD;
  return L[x-1];
}

int LW(int x) { return L[x-1];}

int PB(int x) { return P[x+1];}

int PW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (P[x+1]-P[x+k+1]+MOD)%MOD;
  return P[x+1];
}

int AB(int x) { return A[x+1];}

int AW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (A[x+1]+P[x+k+1])%MOD;
  return A[x+1];
}

int main()
{
  scanf("%d %d", &n, &k);
  scanf("%s", in+1);

  for(int i=1; i<=n; i++)
  {
    B[i]=B[i-1], W[i]=W[i-1];
    if(in[i]=='B') B[i]++;
    if(in[i]=='W') W[i]++;
  }

  L[0]=1;
  for(int i=1; i<=n; i++)
    if(i<=k)
    {
      L[i]=L[i-1];
      if(in[i]=='X') L[i]=(2*L[i])%MOD;
      if(i==k && ileW(1,k)==0) L[i]=(L[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') L[i]=LB(i);
      if(in[i]=='W') L[i]=LW(i);
      if(in[i]=='X') L[i]=(LB(i)+LW(i))%MOD;
    }

  P[n+1]=1;
  for(int i=n; i>=1; i--)
    if(i+k-1>=n)
    {
      P[i]=P[i+1];
      if(in[i]=='X') P[i]=(2*P[i])%MOD;
      if(i+k-1==n && ileB(i,n)==0) A[i]=1, P[i]=(P[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') P[i]=PB(i), A[i]=AB(i);
      if(in[i]=='W') P[i]=PW(i), A[i]=AW(i);
      if(in[i]=='X') P[i]=(PB(i)+PW(i))%MOD, A[i]=(AB(i)+AW(i))%MOD;
    }

  ll result=0;
  for(int i=1; i+k-1<=n; i++)
  {
    if(ileW(i,i+k-1)>0) continue;

    if(i==1) result+=ll(L[i-1])*ll(A[i+k]);
    else if(in[i-1]!='B') result+=ll(L[i-2])*ll(A[i+k]);

    result%=MOD;
  }

  printf("%lld\n", result);

  return 0;
}


#include <cstdio>

typedef long long ll;

const int MOD=1000000007;
const int MAXN=1000006;

char in[MAXN];
int n, k;
ll B[MAXN], W[MAXN], L[MAXN], P[MAXN], A[MAXN];

int ileB(int x, int y) {return (y>=x) ? B[y]-B[x-1] : 0;}
int ileW(int x, int y) {return (y>=x) ? W[y]-W[x-1] : 0;}

int LB(int x)
{
  if(ileW(x-k+1,x-1)==0 && in[x-k]!='B') return (L[x-1]-L[x-k-1]+MOD)%MOD;
  return L[x-1];
}

int LW(int x)
{
  return L[x-1];
}

int PB(int x)
{
  return P[x+1];
}

int PW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (P[x+1]-P[x+k+1]+MOD)%MOD;
  return P[x+1];
}

int AB(int x)
{
  return A[x+1];
}

int AW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (A[x+1]+P[x+k+1])%MOD;
  return A[x+1];
}

int main()
{
  scanf("%d %d", &n, &k);
  scanf("%s", in+1);

  for(int i=1; i<=n; i++)
  {
    B[i]=B[i-1], W[i]=W[i-1];
    if(in[i]=='B') B[i]++;
    if(in[i]=='W') W[i]++;
  }

  L[0]=1;
  for(int i=1; i<=n; i++)
    if(i<=k)
    {
      L[i]=L[i-1];
      if(in[i]=='X') L[i]=(2*L[i])%MOD;
      if(i==k && ileW(1,k)==0) L[i]=(L[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') L[i]=LB(i);
      if(in[i]=='W') L[i]=LW(i);
      if(in[i]=='X') L[i]=(LB(i)+LW(i))%MOD;
    }

  P[n+1]=1;
  for(int i=n; i>=1; i--)
    if(i+k-1>=n)
    {
      P[i]=P[i+1];
      if(in[i]=='X') P[i]=(2*P[i])%MOD;
      if(i+k-1==n && ileB(i,n)==0) A[i]=1, P[i]=(P[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') P[i]=PB(i), A[i]=AB(i);
      if(in[i]=='W') P[i]=PW(i), A[i]=AW(i);
      if(in[i]=='X') P[i]=(PB(i)+PW(i))%MOD, A[i]=(AB(i)+AW(i))%MOD;
    }

  ll result=0;

  for(int i=1; i+k-1<=n; i++)
  {
    if(ileW(i,i+k-1)>0) continue;

    if(i==1) result+=ll(L[i-1])*ll(A[i+k]);
    else if(in[i-1]!='B') result+=ll(L[i-2])*ll(A[i+k]);

    result%=ll(MOD);
  }

  printf("%lld\n", result);

  return 0;
}


#include <cstdio>

typedef long long ll;

const int MOD=1000000007;
const int MAXN=1000006;

char in[MAXN];
int n, k;
ll B[MAXN], W[MAXN], L[MAXN], P[MAXN], A[MAXN];

int ileB(int x, int y) {return (y>=x) ? B[y]-B[x-1] : 0;}
int ileW(int x, int y) {return (y>=x) ? W[y]-W[x-1] : 0;}

int LB(int x)
{
  if(ileW(x-k+1,x-1)==0 && in[x-k]!='B') return (L[x-1]-L[x-k-1]+MOD)%MOD;
  return L[x-1];
}

int LW(int x)
{
  return L[x-1];
}

int PB(int x)
{
  return P[x+1];
}

int PW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (P[x+1]-P[x+k+1]+MOD)%MOD;
  return P[x+1];
}

int AB(int x)
{
  return A[x+1];
}

int AW(int x)
{
  if(ileB(x+1,x+k-1)==0 && in[x+k]!='W') return (A[x+1]+P[x+k+1])%MOD;
  return A[x+1];
}

int main()
{
  scanf("%d %d", &n, &k);
  scanf("%s", in+1);

  for(int i=1; i<=n; i++)
  {
    B[i]=B[i-1], W[i]=W[i-1];
    if(in[i]=='B') B[i]++;
    if(in[i]=='W') W[i]++;
  }

  L[0]=1;
  for(int i=1; i<=n; i++)
    if(i<=k)
    {
      L[i]=L[i-1];
      if(in[i]=='X') L[i]=(2*L[i])%MOD;
      if(i==k && ileW(1,k)==0) L[i]=(L[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') L[i]=LB(i);
      if(in[i]=='W') L[i]=LW(i);
      if(in[i]=='X') L[i]=(LB(i)+LW(i))%MOD;
    }

  P[n+1]=1;
  for(int i=n; i>=1; i--)
    if(i+k-1>n)
    {
      P[i]=P[i+1];
      if(in[i]=='X') P[i]=(2*P[i])%MOD;
      if(i+k-1==n && ileB(i,n)==0) A[i]=1, P[i]=(P[i]-1+MOD)%MOD;
    }
    else
    {
      if(in[i]=='B') P[i]=PB(i), A[i]=AB(i);
      if(in[i]=='W') P[i]=PW(i), A[i]=AW(i);
      if(in[i]=='X') P[i]=(PB(i)+PW(i))%MOD, A[i]=(AB(i)+AW(i))%MOD;
    }

  ll result=0;

  for(int i=1; i+k-1<=n; i++)
  {
    if(ileW(i,i+k-1)>0) continue;

    if(i==1) result+=ll(L[i-1])*ll(A[i+k]);
    else if(in[i-1]!='B') result+=ll(L[i-2])*ll(A[i+k]);

    result%=ll(MOD);
  }

  printf("%lld\n", result);

  return 0;
}


#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }

const int mod = 1000000000 + 7;

int n;
int m;

int rb[1000001], rw[1000001];
string s;

int power (int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = ((ll)c * a) % mod;
        a = ((ll)a * a) % mod;
        b /= 2;
    }
    re c;
}

int main () {
    scanf ("%d%d", &n, &m);
    cin >> s;
    int cur = 0, cnt = 0, all = 0, all2 = 0;
    for (int i = 0; i < n; i++) {
        if (i - m >= 0 && s[i - m] == 'X') {
            cnt++;
            all2 = (all2 * 2) % mod;
        }
        if (s[i] == 'W') cur = 0; else cur++;
        if (cur >= m) {
            int tmp = power (2, cnt);
            rb[i] = ((ll)tmp - all - all2 + 2 * mod) % mod;
        }
        all = (all + rb[i]) % mod;
        if (i - m >= 0) {
            all = (all - rb[i - m] + mod) % mod;
            all2 = (all2 + rb[i - m]) % mod;
        }
    }
    cur = cnt = all = all2 = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (i + m < n && s[i + m] == 'X') {
            cnt++;
            all2 = (all2 * 2) % mod;
        }
        if (s[i] == 'B') cur = 0; else cur++;
        if (cur >= m) {
            int tmp = power (2, cnt);
            rw[i] = ((ll)tmp - all - all2 + 2 * mod) % mod;
        }
        all = (all + rw[i]) % mod;
        if (i + m < n) {
            all = (all - rw[i + m] + mod) % mod;
            all2 = (all2 + rw[i + m]) % mod;
        }
    }
    int ans = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
//      printf ("%d %d\n", rb[i], rw[i]);
        ans = (ans + (ll)sum * rw[i]) % mod;
        if (s[i] == 'X') sum = (2 * sum) % mod;
        sum = (sum + rb[i]) % mod;
    }
    printf ("%d\n", ans);
    return 0;
}


#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }

const int mod = 1000000000 + 7;

int n;
int m;

int rb[1000001], rw[1000001];
string s;

int power (int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = ((ll)c * a) % mod;
        a = ((ll)a * a) % mod;
        b /= 2;
    }
    re c;
}

int main () {
    scanf ("%d%d", &n, &m);
    cin >> s;
    int cur = 0, cnt = 0, all = 0, all2 = 0;
    for (int i = 0; i < n; i++) {
        if (i - m >= 0 && s[i - m] == 'X') {
            cnt++;
            all2 = (all2 * 2) % mod;
        }
        if (s[i] == 'W') cur = 0; else cur++;
        if (cur >= m) {
            int tmp = power (2, cnt);
            rb[i] = ((ll)tmp - all - all2 + 2 * mod) % mod;
        }
        all = (all + rb[i]) % mod;
        if (i - m >= 0) {
            all = (all - rb[i - m] + mod) % mod;
            all2 = (all2 + rb[i - m]) % mod;
        }
    }
    cur = cnt = all = all2 = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (i + m >= 0 && s[i + m] == 'X') {
            cnt++;
            all2 = (all2 * 2) % mod;
        }
        if (s[i] == 'B') cur = 0; else cur++;
        if (cur >= m) {
            int tmp = power (2, cnt);
            rw[i] = ((ll)tmp - all - all2 + 2 * mod) % mod;
        }
        all = (all + rw[i]) % mod;
        if (i + m < n) {
            all = (all - rw[i + m] + mod) % mod;
            all2 = (all2 + rw[i + m]) % mod;
        }
    }
    int ans = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans + (ll)sum * rw[i]) % mod;
        if (s[i] == 'X') sum = (2 * sum) % mod;
        sum = (sum + rb[i]) % mod;
    }
    printf ("%d\n", ans);
    return 0;
}


#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }

const int mod = 1000000000 + 7;

int n;
int m;

int rb[1000001], rw[1000001];
string s;

int power (int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = ((ll)c * a) % mod;
        a = ((ll)a * a) % mod;
        b /= 2;
    }
    re c;
}

int main () {
    scanf ("%d%d", &n, &m);
    cin >> s;
    int cur = 0, cnt = 0, all = 0, all2 = 0;
    for (int i = 0; i < n; i++) {
        if (i - m >= 0 && s[i - m] == 'X') {
            cnt++;
            all2 = (all2 * 2) % mod;
        }
        if (s[i] == 'W') cur = 0; else cur++;
        if (cur >= m) {
            int tmp = power (2, cnt);
            rb[i] = ((ll)tmp - all - all2 + 2 * mod) % mod;
        }
        all = (all + rb[i]) % mod;
        if (i - m >= 0) {
            all = (all - rb[i - m] + mod) % mod;
            all2 = (all2 + rb[i - m]) % mod;
        }
    }
    cur = cnt = all = all2 = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (i + m < n && s[i + m] == 'X') {
            cnt++;
            all2 = (all2 * 2) % mod;
        }
        if (s[i] == 'B') cur = 0; else cur++;
        if (cur >= m) {
            int tmp = power (2, cnt);
            rw[i] = ((ll)tmp - all - all2 + 2 * mod) % mod;
        }
        all = (all + rw[i]) % mod;
        if (i + m < n) {
            all = (all - rw[i + m] + mod) % mod;
            all2 = (all2 + rw[i + m]) % mod;
        }
    }
    int ans = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        printf ("%d %d\n", rb[i], rw[i]);
        ans = (ans + (ll)sum * rw[i]) % mod;
        if (s[i] == 'X') sum = (2 * sum) % mod;
        sum = (sum + rb[i]) % mod;
    }
    printf ("%d\n", ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;

const int N = 1000050;
const LL modu = LL(1e9) + 7;

LL dw[N], db[N], tmp[N];
char str[N];
int n, k;

inline void build (char ty, LL f[])
{
	f[0] = tmp[0] = 1; str[0] = '%';
	for (int i = 1, cc = 0; i <= n; ++i)
	{
		if (str[i] != ty && str[i] != 'X') cc = 0; else ++cc;
		if (cc >= k && str[i - k] != ty) f[i] = tmp[(i == k) ? 0 : (i - k - 1)]; else f[i] = 0;
		tmp[i] = tmp[i - 1]; if (str[i] == 'X') tmp[i] = tmp[i] * 2 % modu;
		tmp[i] = (tmp[i] + modu - f[i]) % modu;
	}
}

int main ()
{
	scanf("%d%d", &n, &k);
	scanf("%s", str + 1);
	build('B', db);
	reverse(str + 1, str + 1 + n); build('W', dw);
	reverse(dw + 1, dw + n + 1); reverse(str + 1, str + n + 1);
	LL cur(0), res(0);
	for (int i = 1; i <= n; ++i)
	{
		if (str[i] == 'X') cur = cur * 2 % modu;
		cur = (cur + db[i]) % modu;
		res = (res + cur * dw[i + 1]) % modu;
	}
	printf("%d\n", int(res));
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;

const int N = 100050;
const LL modu = LL(1e9) + 7;

LL dw[N], db[N], tmp[N];
char str[N];
int n, k;

inline void build (char ty, LL f[])
{
	f[0] = tmp[0] = 1; str[0] = '%';
	for (int i = 1, cc = 0; i <= n; ++i)
	{
		if (str[i] != ty && str[i] != 'X') cc = 0; else ++cc;
		if (cc >= k && str[i - k] != ty) f[i] = tmp[(i == k) ? 0 : (i - k - 1)]; else f[i] = 0;
		tmp[i] = tmp[i - 1]; if (str[i] == 'X') tmp[i] = tmp[i] * 2 % modu;
		tmp[i] = (tmp[i] + modu - f[i]) % modu;
	}
}

int main ()
{
	scanf("%d%d", &n, &k);
	scanf("%s", str + 1);
	build('B', db);
	reverse(str + 1, str + 1 + n); build('W', dw);
	reverse(dw + 1, dw + n + 1); reverse(str + 1, str + n + 1);
	LL cur(0), res(0);
	for (int i = 1; i <= n; ++i)
	{
		if (str[i] == 'X') cur = cur * 2 % modu;
		cur = (cur + db[i]) % modu;
		res = (res + cur * dw[i + 1]) % modu;
	}
	printf("%d\n", int(res));
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

const int N = 1000100;
const int MOD = 1000000007;
int n,m;
char s[N];
int ar[N];
ll dp[N];
ll sdp[N];
int sb[N],sw[N],sx[N];

ll power(ll a, ll b, int mod = MOD) {
    ll res = 1, t = a;
    while (b) {
        if (b&1) res = res*t % mod;
        t = t*t % mod;
        b >>= 1;
    }
    return res;
}

ll dpb[N];
int Ans() {
    sb[0] = sw[0] = sx[0] = 0;
    for (int i = 1; i <= n; ++i) {
        sb[i] = sb[i-1];
        sw[i] = sw[i-1];
        sx[i] = sx[i-1];
        if (ar[i] == 1) ++sb[i];
        if (ar[i] == 2) ++sw[i];
        if (ar[i] == 3) ++sx[i];
    }

    for (int i = 0; i < m; ++i) {
        dp[i] = 0;
        sdp[i] = 0;
    }

    dp[m] = 0;
    sdp[m] = 0;
    if (sw[m] - sw[0] == 0) {
        dp[m] = 1;
        sdp[m] = 1;
    }

    for (int i = m + 1; i <= n; ++i) {
        dp[i] = 0;
        if (ar[i - m] != 1 && sw[i] - sw[i - m] == 0) {
            dp[i] += (power(2,sx[i-m-1]) - sdp[i - m - 1] + MOD);
            dp[i] %= MOD;
        }
        if (ar[i] == 3) {
            sdp[i] = dp[i] + 2*sdp[i-1];
        } else {
            sdp[i] = dp[i] + sdp[i-1];
        }
        sdp[i] %= MOD;
    }

    for (int i = 1; i <= n; ++i) dpb[i] = dp[i];

    //cout << dp[3] << endl;

    reverse(ar+1,ar+n + 1);
    sb[0] = sw[0] = sx[0] = 0;
    for (int i = 1; i <= n; ++i) {
        sb[i] = sb[i-1];
        sw[i] = sw[i-1];
        sx[i] = sx[i-1];
        if (ar[i] == 1) ++sb[i];
        if (ar[i] == 2) ++sw[i];
        if (ar[i] == 3) ++sx[i];
    }

    for (int i = 0; i < m; ++i) {
        dp[i] = 0;
        sdp[i] = 0;
    }

    dp[m] = 0;
    sdp[m] = 0;
    if (sb[m] - sb[0] == 0) {
        dp[m]  = 1;
        sdp[m] = 1;
    }

    for (int i = m + 1; i <= n; ++i) {
        dp[i] = 0;
        if (ar[i - m] != 2 && sb[i] - sb[i - m] == 0) {
            dp[i] += (power(2,sx[i-m-1]) - sdp[i - m - 1] + MOD);
            dp[i] %= MOD;
        }
        if (ar[i] == 3) {
            sdp[i] = dp[i] + 2*sdp[i-1];
        } else {
            sdp[i] = dp[i] + sdp[i-1];
        }
        sdp[i] %= MOD;
    }

    //cout << dp[3] << endl;
    //cout << sdp[2] << endl;
    ll res = 0;
    for (int i = 1; i <= n; ++i) {
        res += dpb[i]*sdp[n-i];
        //cout << dpb[i] <<" " << sdp[n-i] << endl;
        res %= MOD;
    }
    return res;
}
int main() {
    while (scanf("%d%d",&n,&m) == 2) {
        scanf("%s",s);
        for (int i = 0; i < n; ++i) {
            if (s[i] == 'B') ar[i + 1] = 1;
            if (s[i] == 'W') ar[i + 1] = 2;
            if (s[i] == 'X') ar[i + 1] = 3;
        }
        cout << Ans() << endl;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Promlemo2 {
    public static void main(String[] args) throws IOException {
        solve();

    }
    static List<String> lyrics = new ArrayList<>();
    private static void solve() throws IOException {
        PrintWriter printWriter = new PrintWriter(System.out);
        InputStreamReader reader = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(reader);

        int wordsCount = Integer.parseInt(br.readLine());

        Map<Integer, List<Word>> wordsMap = new HashMap<>();

        for(int i=0; i<wordsCount;i++){
            Word word = new Word(br.readLine());
            int vowelCount = word.getVowelCount();
            if(!wordsMap.containsKey(vowelCount))
                wordsMap.put(vowelCount,new ArrayList<>());
            wordsMap.get(vowelCount).add(word);
        }

        List<ValidCombo> secondWordsList =  new ArrayList<>();
        List<ValidCombo> firstWordsList = new ArrayList<>();

        wordsMap.keySet().forEach(k->{
            secondWordsList.addAll(findValidSecondWords(wordsMap.get(k)));
            firstWordsList.addAll(findValidFirstWords(wordsMap.get(k)));
        });

        while (secondWordsList.size() > firstWordsList.size() + 1){
            ValidCombo validCombo = secondWordsList.get(0);
            firstWordsList.add(validCombo);
            secondWordsList.remove(validCombo);
        }

        for (int i = 0; i < secondWordsList.size() && i < firstWordsList.size(); i++) {
           constructLyrics(firstWordsList.get(i),secondWordsList.get(i));
        }

        printWriter.println(lyrics.size());
        lyrics.forEach(printWriter::println);

        printWriter.flush();
    }

    private static List<ValidCombo> findValidFirstWords(List<Word> words) {
        List<ValidCombo> combos = new ArrayList<>();
        for (int word = 0; word+1 < words.size(); word++) {
            Word word1 = words.get(word);
            Word word2 = words.get(++word);
            combos.add(new ValidCombo(word1, word2));
        }
        return combos;
    }

    private static List<ValidCombo> findValidSecondWords(List<Word> words) {
        List<ValidCombo> combos = new ArrayList<>();
        for (int word = 0; word < words.size(); word++) {
            for (int secondWord = word+1; secondWord < words.size(); secondWord++) {
                Word word1 = words.get(word);
                Word word2 = words.get(secondWord);
                if(word1.getEndingVowel() == word2.getEndingVowel()){
                    combos.add(new ValidCombo(word1, word2));
                    words.remove(word1);
                    words.remove(word2);
                    word--;
                    break;
                }
            }
        }
        return combos;
    }

    static void constructLyrics(ValidCombo firstWords, ValidCombo secondWords){
        lyrics.add(firstWords.word1.toString() + " " + secondWords.word1.toString() +
                "\n" + firstWords.word2.toString() + " " + secondWords.word2.toString());
    }

    private static class ValidCombo {
        Word word1;

        Word word2;

        public ValidCombo(Word word1, Word word2){
            this.word1 = word1;
            this.word2 = word2;
        }

        @Override
        public String toString() {
            return word1.toString() + ":" + word2.toString();
        }
    }

    private static class Word{
        private int vowelCount;

        private char endingVowel;
        private String line;

        public Word(String line){
            this.line = line;
            vowelCount = 0;
            for(char c : line.toCharArray()){
                if(c == 'a' || c == 'e' || c == 'o' || c == 'u' || c == 'i'){
                    vowelCount++;
                    endingVowel = c;
                }
            }
        }

        @Override
        public String toString(){
            return line;
        }

        public int getVowelCount() {
            return vowelCount;
        }

        public char getEndingVowel() {
            return endingVowel;
        }

    }

}