#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cstdio>
using namespace std;
int main()
{
    int n,m,i;
    scanf("%d%d",&n,&m);
    if(n>4&&m==3)
    {
        printf("-1\n");
    }
    else
    {
        for(i=0; i<m; ++i)
        {
            printf("%d %d\n",i,i*i+111111);
        }
        n=n-m;
        for(i=0;i<n;++i)
        {
            printf("%d %d\n",i,i*i-111111);
        }
    }
    return 0;
}

/*inmrnlgjiggkrrgfnadnnjkjlfeqcngkhthmkoosambjjhpcas*/


#include<cstdio>
#include<cmath>
#define pi 3.1415
int x[200],y[200];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(m==3&&n>4)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=1;i<=m;i++)
    {
        printf("%d %d\n",i,i*i);
    }
    for(int i=1;i<=n-m;i++)
    {
        printf("%d %d\n",-i,-i*i);
    }
    return 0;
}

/*kcehjecanahrjeqfmmshfpkthpfajgclisskcmchebegfalrfb*/


#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cstdio>
using namespace std;
int main()
{
    int n,m,i;
    scanf("%d%d",&n,&m);
    if(n>4&&m==3)
    {
        printf("-1\n");
    }
    else
    {
        for(i=0; i<m; ++i)
        {
            printf("%d %d\n",i,i*i+100000);
        }
        n=n-m;
        for(i=0;i<n;++i)
        {
            printf("%d %d\n",i,-i*i-100000);
        }
    }
    return 0;
}

/*rqecmecdgphfjlpcabioasaccaqnkdoimtcepehcloharpckic*/


#include <iostream>
#include <cstdio>
using namespace std;

# define MAX 1000000

int main()
{
    int m,n,i;
    while(cin >> n >> m)
    {
        if(m == 3 && n >= 5)
        {
            cout << -1 << endl;
            continue;
        }
        for(i=0; i<m; i++)
        {
            printf("%d %d\n",i,i*i);
        }
        for(i=0; i<n-m; i++)
        {
            printf("%d %d\n",-i,-(i*i)-MAX);
        }
    }
    return 0;
}

/*njatmnfdimrtsbdnimomemlmppqngrnlgfkkthnttcsjebcegq*/


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;

static const int MODVAL = 1000000007;
struct mint
{
	int val;
	mint():val(0){}
	mint(int    x):val(x%MODVAL) {}
	mint(size_t x):val(x%MODVAL) {}
	mint(LL     x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }

mint solve(const string& S, int K)
{
	deque<mint> Bseq(1, 1);
	vector<mint> Bdone(S.size()+1);
	mint Bsigma = 1;
	mint Balready_done = 0;
	for(int i=0; i<S.size(); ++i)
	{
		if( S[i]=='B' )
			Bseq.push_front(0);
		else if( S[i]=='W' )
			Bseq.assign(1, Bsigma);
		else {
			Bseq.push_front(Bsigma);
			Bsigma *= 2;
			Balready_done *= 2;
		}
		if(K < Bseq.size()) {
			Bsigma -= Bseq[K];
			Balready_done += Bseq[K];
		}
		while(K < Bseq.size())
			Bseq.pop_back();
		Bdone[i+1] = Balready_done;
	}

	deque<mint> Wseq(1, 1);
	vector<mint> Wdone(S.size());
	mint Wsigma = 1;
	mint Walready_done = 0;
	for(int i=S.size()-1; i>=0; --i)
	{
		if( S[i]=='W' )
			Wseq.push_front(0);
		else if( S[i]=='B' )
			Wseq.assign(1, Wsigma);
		else {
			Wseq.push_front(Wsigma);
			Wsigma *= 2;
			Walready_done *= 2;
		}
		if(K < Wseq.size()) {
			Wsigma -= Wseq[K];
			Walready_done += Wseq[K];
		}
		while(K < Wseq.size())
			Wseq.pop_back();
		Wdone[i] = Walready_done;
	}

	vector<bool> allBpossible(S.size());
	int lastW = S.size();
	for(int i=S.size()-1; i>=0; --i)
	{
		if( S[i]=='W' )
			lastW = i;
		allBpossible[i] = (i+K <= lastW);
	}

	mint total = 0;
	mint two_pow_X = 1;
	for(int i=0; i+K+K<=S.size(); ++i)
	{
		if( allBpossible[i] ) {
			if( i==0 || S[i-1]!='B' ) {
				total += (i==0 ? 1 : two_pow_X - Bdone[i-1]) * Wdone[i+K];
			}
		}
		if( i-1>=0 && S[i-1]=='X' )
			two_pow_X *= 2;
	}
	return total;
}

int main()
{
	for(int N,K; cin>>N>>K; )
	{
		string S;
		cin >> S;
		cout << solve(S, K).val << endl;
	}
}


#define SUBMIT

#ifdef SUBMIT
#define LOGLEVEL 0
#define NDEBUG
#else
#define LOGLEVEL 1
#endif

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <array>
#include <type_traits>
#include <queue>
#include <stack>
#include <functional>
#include <sstream>

using namespace std;

#define LOG(l, x) if (l <= LOGLEVEL) cout << x << endl

#define int64 long long
#define repeat(x) for (auto repeat_var = 0; repeat_var < x; ++repeat_var)

#define for_inc(i, x) for (auto i = 0; i < x; ++i)
#define for_dec(i, x) for (auto i = x - 1; i >= 0; --i)
#define for_inc_range(i, x, y) for (auto i = x; i <= y; ++i)
#define for_dec_range(i, x, y) for (auto i = x; i >= y; --i)

#define fill0(x) memset(x, 0, sizeof(x))
#define INT_INF ((int)2E9L)
#define INT64_INF ((int64)1E18L)
#define MOD 1000000007
int MODP(int64 x) {
  int r = x % MOD;
  if (r < 0) r += MOD;
  return r;
}

void testGen() {
  freopen("biginput1.txt", "w", stdout);
  fclose(stdout);
}

#define MAX 1000100

char a[MAX];
int f[MAX], g[MAX];
int ff[2][MAX];
int f2[MAX], g2[MAX], ff2[2][MAX], gg2[2][MAX];
int prevB[MAX], prevW[MAX];
int total;

inline char getA(int i) {
  if (i == 0) return 'X';
  return a[i - 1];
}

inline int getG(int i) {
  if (i <= 0) return 1;
  return g[i];
}

inline int getG2(int i) {
  if (i <= 0) return 0;
  return g2[i];
}

int main() {
  ios::sync_with_stdio(false);
#ifndef SUBMIT
  freopen("input1.txt", "r", stdin);
#endif
  int n, k;
  scanf("%d%d", &n, &k);
  scanf("%s", a);

  total = 1;

  prevB[0] = 0;
  prevW[0] = 0;
  for_inc_range(i, 1, n) {
    if (getA(i) == 'B') {
      prevB[i] = i;
    } else {
      prevB[i] = prevB[i - 1];
    }

    if (getA(i) == 'W') {
      prevW[i] = i;
    } else {
      prevW[i] = prevW[i - 1];
    }
  }

  f[0] = 0;
  g[0] = 1;

  for_inc_range(i, 1, n) {
    char c = getA(i);

    if (c == 'X') {
      total = (total * 2) % MOD;
    }

    if (c != 'X') {
      f[i] = f[i - 1];

      if (c == 'B' && prevW[i] < i - k + 1 && i - k + 1>= 1 && getA(i - k) != 'B') {
        f[i] = (f[i] + getG(i - k - 1)) % MOD;
      }

      if (c == 'W') {
        ff[0][i] = f[i];
        ff[1][i] = 0;
      } else {
        ff[0][i] = 0;
        ff[1][i] = f[i];
      }
    } else {
      if (prevW[i] < i - k + 1 && i - k + 1 >= 1 && getA(i - k) != 'B') {
        f[i] = getG(i - k - 1);
      }
      ff[0][i] = f[i - 1];
      ff[1][i] = (f[i] + f[i - 1]) % MOD;
      f[i] = (f[i] + MODP(f[i - 1] * 2)) % MOD;
    }

    g[i] = MODP(total - f[i]);
  }

  LOG(1, f[n]);
  LOG(1, ff[0][n]);
  LOG(1, ff[1][n]);

  f2[0] = 0;
  g2[0] = 0;

  for_inc_range(i, 1, n) {
    char c = getA(i);

    if (c != 'X') {
      f2[i] = f2[i - 1];
      if (c == 'W' && prevB[i] < i - k + 1 && i - k + 1 >= 1 && getA(i - k) != 'W') {
        f2[i] = (f2[i] + gg2[1][i - k]) % MOD;
      }

      if (c == 'W') {
        ff2[0][i] = f2[i];
        ff2[1][i] = 0;
      } else {
        ff2[0][i] = 0;
        ff2[1][i] = f2[i];
      }
    } else {
      if (prevB[i] < i - k + 1 && i - k + 1 >= 1 && getA(i - k) != 'W') {
        f2[i] = gg2[1][i - k];
      }

      ff2[1][i] = f2[i - 1];
      ff2[0][i] = MODP(f2[i] + f2[i - 1]);
      f2[i] = MODP(f2[i] + MODP(f2[i - 1] * 2));
    }

    g2[i] = MODP(f[i] - f2[i]);
    gg2[0][i] = MODP(ff[0][i] - ff2[0][i]);
    gg2[1][i] = MODP(ff[1][i] - ff2[1][i]);
    LOG(1, "F " << i << " " << f[i]);
    LOG(1, "F2 " << i << " " << f2[i]);
    LOG(1, "G2 " << i << " " << g2[i]);
  }

  cout << f2[n] << endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <ctime>
#pragma comment (linker, "/STACK:256000000")

using namespace std;

const int maxN = 1100000;
const int P = 1000000007;

void add(int &x, int delta) {
	x += delta;
	if (x >= P) {
		x -= P;
	}
}

int currentVersion = 0;

struct DP {
	int a[2 * maxN];
	int version[2 * maxN];
	int start;
	int lastZero;
	int sum;
	DP() {
		memset(a, 0, sizeof(a));
		memset(version, 0, sizeof(version));
		start = maxN;
		lastZero = -1;
		sum = 0;
	}

	void shift() {
		++currentVersion;
		--start;
	}

	void update(int k, int delta) {
		++currentVersion;
		if (version[start + k] < lastZero) {
			a[start + k] = 0;
		}
		add(a[start + k], delta);
		version[start + k] = currentVersion;
		add(sum, delta);
	}

	void setZero() {
		++currentVersion;
		lastZero = currentVersion;
		sum = 0;
	}

	int get(int k) {
		if (version[start + k] < lastZero) {
			a[start + k] = 0;
		}
		return a[start + k];
	}
};

DP d, c;
int L[maxN], R[maxN];
int n, k;
char s[maxN];
int sumB[maxN], sumW[maxN];

int getBlack(int l, int r) {
	return sumB[r] - (l == 0 ? 0 : sumB[l - 1]);
}

int getWhite(int l, int r) {
	return sumW[r] - (l == 0 ? 0 : sumW[l - 1]);
}

int getX(int l, int r) {
	return (r - l + 1) - getBlack(l, r) - getWhite(l, r);
}

long long dp[maxN];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &k);
	scanf("%s", &s);

	for (int i = 0; i < n; ++i) {
		sumB[i] = (s[i] == 'B');
		sumW[i] = (s[i] == 'W');
		if (i > 0) {
			sumB[i] += sumB[i - 1];
			sumW[i] += sumW[i - 1];
		}
	}

	d.update(0, 1);
	L[0] = 1;
	for (int i = 0; i < n; ++i) {
		int sum = d.sum;
		if (s[i] == 'B') {
			d.shift();
			int value = d.get(k);
			if (value > 0) {
				d.update(k, P - value);
			}
		} else if (s[i] == 'W') {
			d.setZero();
			d.update(0, sum);
		} else {
			d.shift();
			d.update(0, sum);
			int value = d.get(k);
			if (value > 0) {
				d.update(k, P - value);
			}
		}
		L[i + 1] = d.get(0);
	}

	c.update(0, 1);
	R[n] = 1;
	for (int i = n - 1; i >= 0; --i) {
		int sum = c.sum;
		if (s[i] == 'W') {
			c.shift();
			int value = c.get(k);
			if (value > 0) {
				c.update(k, P - value);
			}
		} else if (s[i] == 'B') {
			c.setZero();
			c.update(0, sum);
		} else {
			c.shift();
			c.update(0, sum);
			int value = c.get(k);
			if (value > 0) {
				c.update(k, P - value);
			}
		}
		R[i] = c.get(0);
	}

	long long res = 0;
	for (int i = k - 1; i + k < n; ++i) {
		long long coef = (s[i] == 'X' ? 2 : 1);
		bool can = (getWhite(i - k + 1, i) == 0);
		dp[i + 1] += dp[i] * coef;
		dp[i + 1] %= P;

		if (can) {
			dp[i + 1] += L[i - k + 1];
			dp[i + 1] %= P;
		}

		{
			bool can = (getBlack(i + 1, i + k) == 0);
			if (can) {
				res += dp[i + 1] * (long long)(R[i + k + 1]);
				res %= P;
			}
		}
	}

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

	return 0;
}


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

const int NMAX = 1000010, MOD = 1000000007;

int N, K, CntW[NMAX], CntB[NMAX], DpPrefix[NMAX], DpSuffix[NMAX], Cnt, Ans;
char S[NMAX];

int main()
{
   // freopen("d.in", "r", stdin);
   // freopen("d.out", "w", stdout);

    scanf("%i %i\n", &N, &K);
    gets(S + 1);

    for(int i = 1; i <= N; ++ i)
    {
        CntW[i] = CntW[i - 1] + (S[i] == 'W');
        CntB[i] = CntB[i - 1] + (S[i] == 'B');
    }

    S[0] = S[N + 1] = ' ';

    DpPrefix[0] = 1;
    for(int i = 1; i <= N; ++ i)
    {
        DpPrefix[i] = (1LL * DpPrefix[i - 1] * (S[i] == 'X' ? 2 : 1)) % MOD;
        if(i - K + 1 >= 1 && CntW[i] - CntW[i - K] == 0 && S[i - K] != 'B')
        {
            DpPrefix[i] = (DpPrefix[i] - (i - K - 1 >= 0 ? DpPrefix[i - K - 1] : 1)) % MOD;
            if(DpPrefix[i] < 0) DpPrefix[i] += MOD;
        }
    }

    DpSuffix[N + 1] = 1;
    for(int i = N; i; -- i)
    {
        DpSuffix[i] = (1LL * DpSuffix[i + 1] * (S[i] == 'X' ? 2 : 1)) % MOD;
        if(i + K - 1 <= N && CntB[i + K - 1] - CntB[i - 1] == 0 && S[i + K] != 'W')
        {
            DpSuffix[i] = (DpSuffix[i] - (i + K + 1 <= N ? DpSuffix[i + K + 1] : 1)) % MOD;
            if(DpSuffix[i] < 0) DpSuffix[i] += MOD;
        }
    }

    for(int i = N; i; -- i)
    {
        if(i + K - 1 <= N && CntW[i + K - 1] == CntW[i - 1] && S[i - 1] != 'B')
            Ans = (Ans + 1LL * (i - 2 >= 0 ? DpPrefix[i - 2] : 1) * Cnt) % MOD;
        if(i + K - 1 <= N && S[i + K - 1] == 'X')
            Cnt = (1LL * Cnt * 2) % MOD;
        if(i + 2 * K - 2 <= N && CntB[i + 2 * K - 2] == CntB[i + K - 2] && S[i + 2 * K - 1] != 'W')
            Cnt = (Cnt + (i + 2 * K <= N ? DpSuffix[i + 2 * K ] : 1)) % MOD;
    }

    printf("%i\n", Ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long long ll;
#define mod9 1000000009
#define mod7 1000000007
#define N 1000010
int getint(){
    int x=0,tmp=1; char c=getchar();
    while( (c<'0'||c>'9')&&c!='-' ) c=getchar();
    if( c == '-' ) c=getchar() , tmp = -1ll;
    while(c>='0'&&c<='9') x*=10,x+=(c-'0'),c=getchar();
    return x*tmp;
}
int n , k , presb[ N ] , presw[ N ];
ll dpb[ N ] , dpw[ N ];
ll dpb2[ N ] , dpw2[ N ];
char c[ N ];
void init(){
    n = getint(); k = getint();
    scanf( "%s" , c + 1 );
    for( int i = 1 ; i <= n ; i ++ )
        presb[ i ] = presb[ i - 1 ] + ( c[ i ] == 'B' ) ,
        presw[ i ] = presw[ i - 1 ] + ( c[ i ] == 'W' );
}
void DP1(){
    int prew = 0;
    ll presum = 1; dpw[ 0 ] = 1;
    for( int i = 1 ; i <= n ; i ++ )
        if( c[ i ] == 'B' ) dpw[ i ] = 0;
        else if( c[ i ] == 'W' ){
            while( i - prew > k ) presum -= dpw[ prew ] , prew ++;
            dpw[ i ] = presum;
            prew = i; presum = dpw[ i ];
            dpw[ i ] %= mod7;
            presum %= mod7;
        }else{
            while( i - prew > k ) presum -= dpw[ prew ] , prew ++;
            dpw[ i ] = presum;
//            printf( "%d\n" , prew );
//            printf( "%I64d\n" , presum );
            presum += dpw[ i ];
            dpw[ i ] %= mod7;
            presum %= mod7;
        }

    int preb = n + 1;
    presum = 1; dpb[ n + 1 ] = 1;
    for( int i = n ; i >= 1 ; i -- )
        if( c[ i ] == 'W' ) dpb[ i ] = 0;
        else if( c[ i ] == 'B' ){
            while( preb - i > k ) presum -= dpb[ preb ] , preb --;
            dpb[ i ] = presum;
            preb = i; presum = dpb[ i ];
            dpb[ i ] %= mod7;
            presum %= mod7;
        }else{
            while( preb - i > k ) presum -= dpb[ preb ] , preb --;
            dpb[ i ] = presum;
            presum += dpb[ i ];
            dpb[ i ] %= mod7;
            presum %= mod7;
        }
}
void DP2(){
    for( int i = k ; i <= n ; i ++ )
        if( presw[ i ] - presw[ i - k ] == 0 ) dpb2[ i ] = dpw[ i - k ];
    for( int i = n - k + 1 ; i >= 1 ; i -- )
        if( presb[ i + k - 1 ] - presb[ i - 1 ] == 0 ) dpw2[ i ] = dpb[ i + k ];
}
void solve(){
    DP1();
    DP2();
    ll ans = 0ll , tmp = 0ll;
    for( int i = n ; i >= k ; i -- ){
        ans += ( dpb2[ i ] * tmp ) % mod7; ans %= mod7;
        if( c[ i ] == 'X' ) tmp = ( tmp * 2ll ) % mod7;
        tmp = ( tmp + dpw2[ i ] ) % mod7;
    }
    printf( "%I64d\n" , ans );
//    for( int i = 1 ; i <= n ; i ++ )
//        printf( "%I64d " , dpb[ i ] ); puts( "" );
//    for( int i = 1 ; i <= n ; i ++ )
//        printf( "%I64d " , dpw[ i ] ); puts( "" );
//    for( int i = 1 ; i <= n ; i ++ )
//        printf( "%I64d " , dpb2[ i ] ); puts( "" );
//    for( int i = 1 ; i <= n ; i ++ )
//        printf( "%I64d " , dpw2[ i ] ); puts( "" );
}
int main(){
    init();
    solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long long ll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define N 1000010
ll getint(){
    ll x=0,tmp=1; char c=getchar();
    while( (c<'0'||c>'9')&&c!='-' ) c=getchar();
    if( c == '-' ) c=getchar() , tmp = -1ll;
    while(c>='0'&&c<='9') x*=10,x+=(c-'0'),c=getchar();
    return x*tmp;
}
ll n , k , presb[ N ] , presw[ N ];
ll dpb[ N ] , dpw[ N ];
ll dpb2[ N ] , dpw2[ N ];
char c[ N ];
void init(){
//    n = getint(); k = getint();
    scanf( "%I64d%I64d" , &n , &k );
    scanf( "%s" , c + 1 );
    for( int i = 1 ; i <= n ; i ++ )
        presb[ i ] = presb[ i - 1 ] + ( c[ i ] == 'B' ) ,
        presw[ i ] = presw[ i - 1 ] + ( c[ i ] == 'W' );
}
void DP1(){
    ll prew = 0ll;
    ll presum = 1ll; dpw[ 0 ] = 1ll;
    for( int i = 1 ; i <= n ; i ++ )
        if( c[ i ] == 'B' ) dpw[ i ] = 0ll;
        else if( c[ i ] == 'W' ){
            while( i - prew > k ){
                presum -= dpw[ prew ] , prew ++;
                if( presum < 0 ) presum += mod7;
            }
            dpw[ i ] = presum;
            prew = i; presum = dpw[ i ];
            dpw[ i ] %= mod7;
            presum %= mod7;
        }else{
            while( i - prew > k ){
                presum -= dpw[ prew ] , prew ++;
                if( presum < 0 ) presum += mod7;
            }
            dpw[ i ] = presum;
            presum += dpw[ i ];
            dpw[ i ] %= mod7;
            presum %= mod7;
        }

    ll preb = n + 1;
    presum = 1; dpb[ n + 1 ] = 1;
    for( int i = n ; i >= 1 ; i -- )
        if( c[ i ] == 'W' ) dpb[ i ] = 0;
        else if( c[ i ] == 'B' ){
            while( preb - i > k ){
                presum -= dpb[ preb ] , preb --;
                if( presum < 0 ) presum += mod7;
            }
            dpb[ i ] = presum;
            preb = i; presum = dpb[ i ];
            dpb[ i ] %= mod7;
            presum %= mod7;
        }else{
            while( preb - i > k ){
                presum -= dpb[ preb ] , preb --;
                if( presum < 0 ) presum += mod7;
            }
            dpb[ i ] = presum;
            presum += dpb[ i ];
            dpb[ i ] %= mod7;
            presum %= mod7;
        }
}
void DP2(){
    for( int i = k ; i <= n ; i ++ )
        if( presw[ i ] - presw[ i - k ] == 0 ) dpb2[ i ] = dpw[ i - k ];
    for( int i = n - k + 1 ; i >= 1 ; i -- )
        if( presb[ i + k - 1 ] - presb[ i - 1 ] == 0 ) dpw2[ i ] = dpb[ i + k ];
}
void solve(){
    DP1();
    DP2();
    ll ans = 0ll , tmp = 0ll;
    for( int i = n ; i >= k ; i -- ){
        ans += ( dpb2[ i ] * tmp ) % mod7; ans %= mod7;
        if( c[ i ] == 'X' ) tmp = ( tmp * 2ll ) % mod7;
        tmp = ( tmp + dpw2[ i ] ) % mod7;
    }
    printf( "%I64d\n" , ans );
//    for( int i = 1 ; i <= n ; i ++ )
//        printf( "%I64d " , dpb[ i ] ); puts( "" );
//    for( int i = 1 ; i <= n ; i ++ )
//        printf( "%I64d " , dpw[ i ] ); puts( "" );
//    for( int i = 1 ; i <= n ; i ++ )
//        printf( "%I64d " , dpb2[ i ] ); puts( "" );
//    for( int i = 1 ; i <= n ; i ++ )
//        printf( "%I64d " , dpw2[ i ] ); puts( "" );
}
int main(){
    init();
    solve();
}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class Main
{
	public final int module = 1000000007;

	public BufferedReader in;
	public PrintStream out;

	public boolean log_enabled = true;

	private class BWString
	{
		public long[] X;
		public long[] A;
		public long[] P;

		BWString(String s, char c, int k, boolean inv)
		{
			int i,l,n = s.length();

			X = new long[n+1];
			A = new long[n+1];
			P = new long[n+1];

			X[0] = 1;
			A[0] = 0;
			P[0] = 0;

			char x,p;

			l = 0;
			for (i=1; i<k; i++)
			{
				A[0] = 0;
				P[0] = 0;

				switch (x = s.charAt( inv ?  n-i  : i-1))
				{
					case 'X':
						X[i] = 2*X[i-1] % module;
						l++;
						break;

					default:
						X[i] = X[i-1];

						if (x == c)
						{
							l++;
						}
						else
						{
							l = 0;
						}
				}

				//logWrite("%d:	X=%d,	A=%d,	P=%d\n", i,X[i],A[i],P[i]);
			}

			for (i=k; i<=n; i++)
			{
				switch (x = s.charAt( inv ?  n-i : i-1))
				{
					case 'X':
						X[i] = 2*X[i-1] % module;
						P[i] = 2*P[i-1] % module;
						l++;
						break;

					default:

						X[i] = X[i-1];
						P[i] = P[i-1];

						if (x == c)
						{
							l++;
						}
						else
						{
							l = 0;
						}
				}

				if (l>=k)
				{
					if (i==k)
					{
						A[i] = 1;
					}
					else
					{
						p = s.charAt( inv ?  n-(i-k)  : (i-k)-1);
						if (p == c)
						{
							A[i] = 0;
						}
						else
						{
							A[i] = (X[i-k-1] - P[i-k-1] + module) % module;
						}
					}

					P[i] = (P[i] + A[i]) % module;
				}
				else
				{
					A[i] = 0;
				}

				//logWrite("%d:	X=%d,	A=%d,	P=%d\n", i,X[i],A[i],P[i]);
			}
		}
	}

	public void test()
	{
		int n = readInt();
		int k = readInt();

		String s = readLn();

		BWString a = new BWString(s, 'B', k, false);
		BWString b = new BWString(s, 'W', k, true);

		long res = 0;

		for (int i=k; i<=n-k; i++)
		{
			res += ( a.A[i]*b.P[n-i] ) % module;
		}

		out.println(res);
	}

	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;

			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));

		}
		catch (Exception e)
		{
			return;
		}

		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)
			{
				test();
			}
		}
	}

	public static void main(String args[])
	{
		new Main().run();
	}

	private StringTokenizer tokenizer = null;

	public int readInt()
	{
        return Integer.parseInt(readToken());
    }

    public long readLong()
	{
        return Long.parseLong(readToken());
    }

    public double readDouble()
	{
        return Double.parseDouble(readToken());
    }

	public String readLn()
	{
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}

    public String readToken()
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }

	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}

	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}

	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}

		out.printf(format, args);
	}
}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class Main
{
	public final int module = 1000000007;

	public BufferedReader in;
	public PrintStream out;

	public boolean log_enabled = true;

	private class BWString
	{
		public long[] X;
		public long[] A;
		public long[] P;

		BWString(String s, char c, int k, boolean inv)
		{
			int i,l,n = s.length();

			X = new long[n+1];
			A = new long[n+1];
			P = new long[n+1];

			X[0] = 1;
			A[0] = 0;
			P[0] = 0;

			char x,p;

			l = 0;
			for (i=1; i<k; i++)
			{
				A[0] = 0;
				P[0] = 0;

				switch (x = s.charAt( inv ?  n-i  : i-1))
				{
					case 'X':
						X[i] = 2*X[i-1] % module;
						l++;
						break;

					default:
						X[i] = X[i-1];

						if (x == c)
						{
							l++;
						}
						else
						{
							l = 0;
						}
				}

				//logWrite("%d:	X=%d,	A=%d,	P=%d\n", i,X[i],A[i],P[i]);
			}

			for (i=k; i<=n; i++)
			{
				switch (x = s.charAt( inv ?  n-i : i-1))
				{
					case 'X':
						X[i] = 2*X[i-1] % module;
						P[i] = 2*P[i-1] % module;
						l++;
						break;

					default:

						X[i] = X[i-1];
						P[i] = P[i-1];

						if (x == c)
						{
							l++;
						}
						else
						{
							l = 0;
						}
				}

				if (l>=k)
				{
					if (i==k)
					{
						A[i] = 1;
					}
					else
					{
						p = s.charAt( inv ?  n-(i-k)  : (i-k)-1);
						if (p == c)
						{
							A[i] = 0;
						}
						else
						{
							A[i] = (X[i-k-1] - P[i-k-1] + module) % module;
						}
					}

					P[i] = (P[i] + A[i]) % module;
				}
				else
				{
					A[i] = 0;
				}

				//logWrite("%d:	X=%d,	A=%d,	P=%d\n", i,X[i],A[i],P[i]);
			}
		}
	}

	public void test()
	{
		int n = readInt();
		int k = readInt();

		String s = readLn();

		BWString a = new BWString(s, 'B', k, false);
		BWString b = new BWString(s, 'W', k, true);

		long res = 0;

		for (int i=k; i<=n-k; i++)
		{
			res = (res + a.A[i]*b.P[n-i] ) % module;
		}

		out.println(res);
	}

	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;

			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));

		}
		catch (Exception e)
		{
			return;
		}

		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)
			{
				test();
			}
		}
	}

	public static void main(String args[])
	{
		new Main().run();
	}

	private StringTokenizer tokenizer = null;

	public int readInt()
	{
        return Integer.parseInt(readToken());
    }

    public long readLong()
	{
        return Long.parseLong(readToken());
    }

    public double readDouble()
	{
        return Double.parseDouble(readToken());
    }

	public String readLn()
	{
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}

    public String readToken()
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }

	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}

	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}

	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}

		out.printf(format, args);
	}
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
	static final long MOD = (long) (1e9 + 7);

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int length = in.readInt();
		int subStringLength = in.readInt();
		if (2 * subStringLength > length) {
			out.printLine(0);
			return;
		}
		char[] s = new char[length];
		for (int i = 0; i < length; i++)
			s[i] = in.readCharacter();
		long[] countDirect = count(s, length, subStringLength, 'B');
		char[] reverse = new char[length];
		for (int i = 0; i < length; i++)
			reverse[i] = s[length - i - 1];
		long[] countReverse = count(reverse, length, subStringLength, 'W');
		long answer = 0;
		long sum = 0;
		for (int i = 0; i + 2 * subStringLength <= length; i++) {
			if (s[i + subStringLength - 1] == 'X') {
				sum *= 2;
				if (sum >= MOD)
					sum -= MOD;
			}
			sum += countDirect[i];
			if (sum >= MOD)
				sum -= MOD;
			answer += sum * countReverse[length - i - 2 * subStringLength] % MOD;
		}
		answer %= MOD;
		out.printLine(answer);
	}

	private long[] count(char[] s, int length, int subStringLength, char good) {
		int countBad = 0;
		long[] count = new long[length];
		long[] result = new long[length];
		if (s[0] == 'X') {
			count[0] = 2;
		} else {
			count[0] = 1;
			if (s[0] != good)
				countBad++;
		}
		for (int i = 1; i < subStringLength; i++) {
			if (s[i] == 'X') {
				count[i] = count[i - 1] * 2;
				if (count[i] >= MOD)
					count[i] -= MOD;
			} else {
				count[i] = count[i - 1];
				if (s[i] != good)
					countBad++;
			}
		}
		if (countBad == 0) {
			result[0] = 1;
			count[subStringLength - 1]--;
		}
		for (int i = subStringLength; i < length; i++) {
			if (s[i] == 'X') {
				count[i] = count[i - 1] * 2;
				if (count[i] >= MOD)
					count[i] -= MOD;
			} else {
				count[i] = count[i - 1];
				if (s[i] != good)
				countBad++;
			}
			if (s[i - subStringLength] != 'X' && s[i - subStringLength] != good)
				countBad--;
			if (countBad == 0 && s[i - subStringLength] != good) {
				result[i - subStringLength + 1] = (i == subStringLength ? 1 : count[i - subStringLength - 1]);
				count[i] -= result[i - subStringLength + 1];
				if (count[i] < 0)
					count[i] += MOD;
			}
		}
		return result;
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}


import java.io.*;
import java.util.*;

public class Main {
//	static Scanner in; static int next() throws Exception {return in.nextInt();};
//	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
	static BufferedReader in;
	static PrintWriter out;

	public static void main(String[] args) throws Exception {
//		in = new Scanner(System.in);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		String[] ss = in.readLine().split(" ");

		int n = Integer.parseInt(ss[0]);
		int k = Integer.parseInt(ss[1]);

		int mod = 1000000007;
		char[] c = in.readLine().toCharArray();

		int[] bcount = new int[n + 1];
		int[] wcount = new int[n + 1];
		int[] xcount = new int[n + 1];

		for (int i = 0; i < n; i++) {
			bcount[i + 1] = bcount[i];
			wcount[i + 1] = wcount[i];
			xcount[i + 1] = xcount[i];
			if (c[i] == 'B') bcount[i + 1]++;
			if (c[i] == 'W') wcount[i + 1]++;
			if (c[i] == 'X') xcount[i + 1]++;
		}

		int[] deg2 = new int[n + 1];
		deg2[0] = 1;
		for (int i = 0; i < n; i++) deg2[i + 1] = (int)((deg2[i] * 2L) % mod);

		int[] kolright = new int[n + 1];
		int[] sumkolright = new int[n + 1];
		for (int i = n - 1; i >= 0; i--) {
			if (i + k <= n && bcount[i + k] - bcount[i] == 0) {
				if (i + k == n) kolright[i] = deg2[0];
				else if (c[i + k] == 'W') kolright[i] = 0;
				else kolright[i] = (int)(((long)deg2[xcount[n] - xcount[i + k + 1]] - sumkolright[i + k + 1] + mod) % mod);
			} else kolright[i] = 0;
			if (c[i] != 'X') sumkolright[i] = (kolright[i] + sumkolright[i + 1]) % mod;
			else sumkolright[i] = (int)((kolright[i] + 2L * sumkolright[i + 1]) % mod);
		}

		int[] kolleft = new int[n + 1];
		int[] sumkolleft = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			if (i >= k && wcount[i] - wcount[i - k] == 0) {
				if (i == k) kolleft[i] = deg2[0];
				else if (c[i - k - 1] == 'B') kolleft[i] = 0;
				else kolleft[i] = (int)(((long)deg2[xcount[i - k - 1] - xcount[0]] - sumkolleft[i - k - 1] + mod) % mod);
			} else kolleft[i] = 0;
			if (c[i - 1] != 'X') sumkolleft[i] = (kolleft[i] + sumkolleft[i - 1]) % mod;
			else sumkolleft[i] = (int)((kolleft[i] + 2L * sumkolleft[i - 1]) % mod);
		}

/*		for (int i = 0; i <= n; i++) out.print(kolleft[i] + " ");
		out.println();
		for (int i = 0; i <= n; i++) out.print(sumkolleft[i] + " ");
		out.println();
		for (int i = 0; i <= n; i++) out.print(kolright[i] + " ");
		out.println();
		for (int i = 0; i <= n; i++) out.print(sumkolright[i] + " ");
		out.println();*/

		long answ = 0;
		for (int i = 1; i < n; i++) answ += (long) kolleft[i] * sumkolright[i] % mod;

		out.println(answ % mod);

		out.close();
	}
}


import java.io.*;
import java.util.*;

public class Main {
//	static Scanner in; static int next() throws Exception {return in.nextInt();};
//	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
	static BufferedReader in;
	static PrintWriter out;

	public static void main(String[] args) throws Exception {
//		in = new Scanner(System.in);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		String[] ss = in.readLine().split(" ");

		int n = Integer.parseInt(ss[0]);
		int k = Integer.parseInt(ss[1]);

		int mod = 1000000007;
		char[] c = in.readLine().toCharArray();

		int[] bcount = new int[n + 1];
		int[] wcount = new int[n + 1];
		int[] xcount = new int[n + 1];

		for (int i = 0; i < n; i++) {
			bcount[i + 1] = bcount[i];
			wcount[i + 1] = wcount[i];
			xcount[i + 1] = xcount[i];
			if (c[i] == 'B') bcount[i + 1]++;
			if (c[i] == 'W') wcount[i + 1]++;
			if (c[i] == 'X') xcount[i + 1]++;
		}

		int[] deg2 = new int[n + 1];
		deg2[0] = 1;
		for (int i = 0; i < n; i++) deg2[i + 1] = (int)(deg2[i] * 2L % mod);

		int[] kolright = new int[n + 1];
		int[] sumkolright = new int[n + 1];
		for (int i = n - 1; i >= 0; i--) {
			if (i + k <= n && bcount[i + k] - bcount[i] == 0) {
				if (i + k == n) kolright[i] = deg2[0];
				else if (c[i + k] == 'W') kolright[i] = 0;
				else kolright[i] = deg2[xcount[n] - xcount[i + k + 1]] - sumkolright[i + k + 1];
			} else kolright[i] = 0;
			if (c[i] != 'X') sumkolright[i] = (kolright[i] + sumkolright[i + 1]) % mod;
			else sumkolright[i] = (int)((kolright[i] + 2L * sumkolright[i + 1]) % mod);
		}

		int[] kolleft = new int[n + 1];
		int[] sumkolleft = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			if (i >= k && wcount[i] - wcount[i - k] == 0) {
				if (i == k) kolleft[i] = deg2[0];
				else if (c[i - k - 1] == 'B') kolleft[i] = 0;
				else kolleft[i] = deg2[xcount[i - k - 1] - xcount[0]] - sumkolleft[i - k - 1];
			} else kolleft[i] = 0;
			if (c[i - 1] != 'X') sumkolleft[i] = (kolleft[i] + sumkolleft[i - 1]) % mod;
			else sumkolleft[i] = (int)((kolleft[i] + 2L * sumkolleft[i - 1]) % mod);
		}

/*		for (int i = 0; i <= n; i++) out.print(kolleft[i] + " ");
		out.println();
		for (int i = 0; i <= n; i++) out.print(sumkolleft[i] + " ");
		out.println();
		for (int i = 0; i <= n; i++) out.print(kolright[i] + " ");
		out.println();
		for (int i = 0; i <= n; i++) out.print(sumkolright[i] + " ");
		out.println();*/

		long answ = 0;
		for (int i = 1; i < n; i++) answ += (long) kolleft[i] * sumkolright[i] % mod;

		out.println(answ % mod);

		out.close();
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class D {
	int MOD = (int)1e9 + 7;

	void do_solve() throws NumberFormatException, IOException {
		int n = _int();
		int k = _int();

		char s[] = _token().toCharArray();

		long b[] = new long[n+1];
		long sumb[] = new long[n+1];
		long b2[] = new long[n+1];

		long w[] = new long[n+1];
		long sumw[] = new long[n+1];
		long w2[] = new long[n+1];

		long t[] = new long[n+1];

		t[0] = 1;
		int cnt = 0, cnt2 = 0;
		for(int i = 1; i <= n; i++) {
			t[i] = t[i-1];
			if (s[i - 1] == 'X') {
				t[i] = (t[i] * 2) % MOD;
			}

			if (s[i-1] != 'W') {
				cnt++;
			}

			if (s[i-1] == 'B') {
				cnt2++;
			}

			if (i >= k+1 && s[i-1-k] == 'B') {
				cnt2--;
			}

			if (i >= k+1 && s[i-k-1] != 'W') {
				cnt--;
			}

			b2[i] += (s[i-1] == 'X' ? 2 : 1 ) * b2[i-1];

			if (cnt == k) {
				b2[i] += t[i - k] - b2[i - k] - sumb[i-1] + sumb[i-k];
				b[i] += t[i - k] - b2[i - k] - sumb[i-1] + sumb[i-k];
			}

			b2[i] %= MOD;
			b[i] %= MOD;
			sumb[i] = (sumb[i-1] + b[i]) % MOD;
		}

		t[n] = 1;
		t[0] = 1;
		cnt = 0; cnt2 = 0;
		for(int i = n-1; i >= 0; i--) {
			t[i] = t[i+1];
			if (s[i] == 'X') {
				t[i] = (t[i] * 2) % MOD;
			}

			if (s[i] != 'B') {
				cnt++;
			}

			if (s[i] == 'W') {
				cnt2++;
			}

			if (i < n-k && s[i+k] == 'W') {
				cnt2--;
			}

			if (i < n-k && s[i+k] != 'B') {
				cnt--;
			}

			w2[i] += (s[i] == 'X' ? 2 : 1 ) * w2[i+1];

			if (cnt == k) {
				w2[i] += t[i + k] - w2[i + k] - sumw[i+1] + sumw[i+k];
				w[i] += t[i + k] - w2[i + k] - sumw[i+1] + sumw[i+k];
			}

			w2[i] %= MOD;
			w[i] %= MOD;
			sumw[i] = (sumw[i+1] + w[i]) % MOD;
		}

		long ans = 0;
		for(int i = 0; i <= n; i++) {
			ans += b[i] * w2[i];
//			debug(i, b[i], b2[i], w2[i]);
			ans %= MOD;
		}
//		debug("");
		out.println((ans + MOD) % MOD);
	}

	void debug(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}

	void mainProgram() throws NumberFormatException, IOException {
		/*
		test("D.in");
		 */
		try {
			init(true, "D");
		} catch (Exception e) {
			init(false, "");
		}
		boolean multy = false;

		if (!multy) {
			while (in.ready() || st.hasMoreTokens()) {
				do_solve();
			}
		} else {
			for (int T = _int(); T > 0; --T) {
				do_solve();
			}
		}
		out.close();
	}

	void init(boolean FILE, String name) throws NumberFormatException,
			IOException {
		Locale.setDefault(Locale.US);
		if (FILE) {
			in = new BufferedReader(new FileReader(name + ".in"));
			out = new PrintWriter(name + ".out");
		} else {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}
		st = new StringTokenizer("");
	}

	void test(String name) throws IOException {
		out = new PrintWriter(new File(name));

		out.close();
	}

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		long T = System.currentTimeMillis();
		new D().mainProgram();
		System.err.println("Time of working: "
				+ (System.currentTimeMillis() - T) + " ms");
	}

	String _token() throws IOException {
		while (in.ready() && !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		if (st.hasMoreTokens())
			return st.nextToken();
		return "";
	}

	BigInteger add(BigInteger A, BigInteger B) {
		return A.add(B);
	}

	BigInteger mult(BigInteger A, BigInteger B) {
		return A.multiply(B);
	}

	BigInteger sub(BigInteger A, BigInteger B) {
		return A.subtract(B);
	}

	BigInteger div(BigInteger A, BigInteger B) {
		return A.divide(B);
	}

	BigInteger mi(BigInteger A) {
		return (BigInteger.ZERO).subtract(A);
	}

	BigInteger sq(BigInteger A) {
		return A.multiply(A);
	}

	BigInteger val(long a) {
		return BigInteger.valueOf(a);
	}

	int cmp(BigInteger a, BigInteger b) {
		return a.compareTo(b);
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	int _int() throws NumberFormatException, IOException {
		return Integer.parseInt(_token());
	}

	long _long() throws NumberFormatException, IOException {
		return Long.parseLong(_token());
	}

	double _double() throws NumberFormatException, IOException {
		return Double.parseDouble(_token());
	}

	int gcd(int a, int b) {
		if (a < 0)
			a = -a;
		if (b < 0)
			b = -b;
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	long gcd(long a, long b) {
		if (a < 0)
			a = -a;
		if (b < 0)
			b = -b;
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	BigInteger gcd(BigInteger a, BigInteger b) {
		if (cmp(a, val(0)) < 0)
			a = mi(a);
		if (cmp(b, val(0)) < 0)
			b = mi(b);
		return a.gcd(b);
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class D {
	int MOD = (int)1e9 + 7;

	void do_solve() throws NumberFormatException, IOException {
		int n = _int();
		int k = _int();

		char s[] = _token().toCharArray();

		long b[] = new long[n+1];
		long sumb[] = new long[n+1];
		long b2[] = new long[n+1];

		long w[] = new long[n+1];
		long sumw[] = new long[n+1];
		long w2[] = new long[n+1];

		long t[] = new long[n+1];

		t[0] = 1;
		int cnt = 0, cnt2 = 0;
		for(int i = 1; i <= n; i++) {
			t[i] = t[i-1];
			if (s[i - 1] == 'X') {
				t[i] = (t[i] * 2) % MOD;
			}

			if (s[i-1] != 'W') {
				cnt++;
			}

			if (s[i-1] == 'B') {
				cnt2++;
			}

			if (i >= k+1 && s[i-1-k] == 'B') {
				cnt2--;
			}

			if (i >= k+1 && s[i-k-1] != 'W') {
				cnt--;
			}

			b2[i] += (s[i-1] == 'X' ? 2 : 1 ) * b2[i-1];

			if (cnt == k) {
				b2[i] += t[i - k] - b2[i - k] - sumb[i-1] + sumb[i-k];
				b[i] += t[i - k] - b2[i - k] - sumb[i-1] + sumb[i-k];
			}

			b[i] %= MOD;
			sumb[i] = (sumb[i-1] + b[i]) % MOD;
		}

		t[n] = 1;
		t[0] = 1;
		cnt = 0; cnt2 = 0;
		for(int i = n-1; i >= 0; i--) {
			t[i] = t[i+1];
			if (s[i] == 'X') {
				t[i] = (t[i] * 2) % MOD;
			}

			if (s[i] != 'B') {
				cnt++;
			}

			if (s[i] == 'W') {
				cnt2++;
			}

			if (i < n-k && s[i+k] == 'W') {
				cnt2--;
			}

			if (i < n-k && s[i+k] != 'B') {
				cnt--;
			}

			w2[i] += (s[i] == 'X' ? 2 : 1 ) * w2[i+1];

			if (cnt == k) {
				w2[i] += t[i + k] - w2[i + k] - sumw[i+1] + sumw[i+k];
				w[i] += t[i + k] - w2[i + k] - sumw[i+1] + sumw[i+k];
			}

			w[i] %= MOD;
			sumw[i] = (sumw[i+1] + w[i]) % MOD;
		}

		long ans = 0;
		for(int i = 0; i <= n; i++) {
			ans += b[i] * w2[i];
//			debug(i, b[i], b2[i], w2[i]);
			ans %= MOD;
		}
//		debug("");
		out.println((ans + MOD) % MOD);
	}

	void debug(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}

	void mainProgram() throws NumberFormatException, IOException {
		/*
		test("D.in");
		 */
		try {
			init(true, "D");
		} catch (Exception e) {
			init(false, "");
		}
		boolean multy = false;

		if (!multy) {
			while (in.ready() || st.hasMoreTokens()) {
				do_solve();
			}
		} else {
			for (int T = _int(); T > 0; --T) {
				do_solve();
			}
		}
		out.close();
	}

	void init(boolean FILE, String name) throws NumberFormatException,
			IOException {
		Locale.setDefault(Locale.US);
		if (FILE) {
			in = new BufferedReader(new FileReader(name + ".in"));
			out = new PrintWriter(name + ".out");
		} else {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}
		st = new StringTokenizer("");
	}

	void test(String name) throws IOException {
		out = new PrintWriter(new File(name));

		out.close();
	}

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		long T = System.currentTimeMillis();
		new D().mainProgram();
		System.err.println("Time of working: "
				+ (System.currentTimeMillis() - T) + " ms");
	}

	String _token() throws IOException {
		while (in.ready() && !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		if (st.hasMoreTokens())
			return st.nextToken();
		return "";
	}

	BigInteger add(BigInteger A, BigInteger B) {
		return A.add(B);
	}

	BigInteger mult(BigInteger A, BigInteger B) {
		return A.multiply(B);
	}

	BigInteger sub(BigInteger A, BigInteger B) {
		return A.subtract(B);
	}

	BigInteger div(BigInteger A, BigInteger B) {
		return A.divide(B);
	}

	BigInteger mi(BigInteger A) {
		return (BigInteger.ZERO).subtract(A);
	}

	BigInteger sq(BigInteger A) {
		return A.multiply(A);
	}

	BigInteger val(long a) {
		return BigInteger.valueOf(a);
	}

	int cmp(BigInteger a, BigInteger b) {
		return a.compareTo(b);
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	int _int() throws NumberFormatException, IOException {
		return Integer.parseInt(_token());
	}

	long _long() throws NumberFormatException, IOException {
		return Long.parseLong(_token());
	}

	double _double() throws NumberFormatException, IOException {
		return Double.parseDouble(_token());
	}

	int gcd(int a, int b) {
		if (a < 0)
			a = -a;
		if (b < 0)
			b = -b;
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	long gcd(long a, long b) {
		if (a < 0)
			a = -a;
		if (b < 0)
			b = -b;
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	BigInteger gcd(BigInteger a, BigInteger b) {
		if (cmp(a, val(0)) < 0)
			a = mi(a);
		if (cmp(b, val(0)) < 0)
			b = mi(b);
		return a.gcd(b);
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class D {
	int MOD = (int)1e9 + 7;

	void do_solve() throws NumberFormatException, IOException {
		int n = _int();
		int k = _int();

		char s[] = _token().toCharArray();

		long b[] = new long[n+1];
		long sumb[] = new long[n+1];
		long b2[] = new long[n+1];

		long w[] = new long[n+1];
		long sumw[] = new long[n+1];
		long w2[] = new long[n+1];

		long t[] = new long[n+1];

		t[0] = 1;
		int cnt = 0, cnt2 = 0;
		for(int i = 1; i <= n; i++) {
			t[i] = t[i-1];
			if (s[i - 1] == 'X') {
				t[i] = (t[i] * 2) % MOD;
			}

			if (s[i-1] != 'W') {
				cnt++;
			}

			if (s[i-1] == 'B') {
				cnt2++;
			}

			if (i >= k+1 && s[i-1-k] == 'B') {
				cnt2--;
			}

			if (i >= k+1 && s[i-k-1] != 'W') {
				cnt--;
			}

			b2[i] += (s[i-1] == 'X' ? 2 : 1 ) * b2[i-1];

			if (cnt == k) {
				b2[i] += t[i - k] - b2[i - k] - sumb[i-1] + sumb[i-k];
				b[i] += t[i - k] - b2[i - k] - sumb[i-1] + sumb[i-k];
			}

			b[i] %= MOD;
			sumb[i] = (sumb[i-1] + b[i]) % MOD;
		}

		t[n] = 1;
		t[0] = 1;
		cnt = 0; cnt2 = 0;
		for(int i = n-1; i >= 0; i--) {
			t[i] = t[i+1];
			if (s[i] == 'X') {
				t[i] = (t[i] * 2) % MOD;
			}

			if (s[i] != 'B') {
				cnt++;
			}

			if (s[i] == 'W') {
				cnt2++;
			}

			if (i < n-k && s[i+k] == 'W') {
				cnt2--;
			}

			if (i < n-k && s[i+k] != 'B') {
				cnt--;
			}

			w2[i] += (s[i] == 'X' ? 2 : 1 ) * w2[i+1];

			if (cnt == k) {
				w2[i] += t[i + k] - w2[i + k] - sumw[i+1] + sumw[i+k];
				w[i] += t[i + k] - w2[i + k] - sumw[i+1] + sumw[i+k];
			}

			w[i] %= MOD;
			sumw[i] = (sumw[i+1] + w[i]) % MOD;
		}

		long ans = 0;
		for(int i = 0; i <= n; i++) {
			ans += b[i] * w2[i];
//			debug(i, b[i], b2[i], w2[i]);
			ans %= MOD;
		}
//		debug("");
		out.println(ans);
	}

	void debug(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}

	void mainProgram() throws NumberFormatException, IOException {
		/*
		test("D.in");
		 */
		try {
			init(true, "D");
		} catch (Exception e) {
			init(false, "");
		}
		boolean multy = false;

		if (!multy) {
			while (in.ready() || st.hasMoreTokens()) {
				do_solve();
			}
		} else {
			for (int T = _int(); T > 0; --T) {
				do_solve();
			}
		}
		out.close();
	}

	void init(boolean FILE, String name) throws NumberFormatException,
			IOException {
		Locale.setDefault(Locale.US);
		if (FILE) {
			in = new BufferedReader(new FileReader(name + ".in"));
			out = new PrintWriter(name + ".out");
		} else {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}
		st = new StringTokenizer("");
	}

	void test(String name) throws IOException {
		out = new PrintWriter(new File(name));

		out.close();
	}

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		long T = System.currentTimeMillis();
		new D().mainProgram();
		System.err.println("Time of working: "
				+ (System.currentTimeMillis() - T) + " ms");
	}

	String _token() throws IOException {
		while (in.ready() && !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		if (st.hasMoreTokens())
			return st.nextToken();
		return "";
	}

	BigInteger add(BigInteger A, BigInteger B) {
		return A.add(B);
	}

	BigInteger mult(BigInteger A, BigInteger B) {
		return A.multiply(B);
	}

	BigInteger sub(BigInteger A, BigInteger B) {
		return A.subtract(B);
	}

	BigInteger div(BigInteger A, BigInteger B) {
		return A.divide(B);
	}

	BigInteger mi(BigInteger A) {
		return (BigInteger.ZERO).subtract(A);
	}

	BigInteger sq(BigInteger A) {
		return A.multiply(A);
	}

	BigInteger val(long a) {
		return BigInteger.valueOf(a);
	}

	int cmp(BigInteger a, BigInteger b) {
		return a.compareTo(b);
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	int _int() throws NumberFormatException, IOException {
		return Integer.parseInt(_token());
	}

	long _long() throws NumberFormatException, IOException {
		return Long.parseLong(_token());
	}

	double _double() throws NumberFormatException, IOException {
		return Double.parseDouble(_token());
	}

	int gcd(int a, int b) {
		if (a < 0)
			a = -a;
		if (b < 0)
			b = -b;
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	long gcd(long a, long b) {
		if (a < 0)
			a = -a;
		if (b < 0)
			b = -b;
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	BigInteger gcd(BigInteger a, BigInteger b) {
		if (cmp(a, val(0)) < 0)
			a = mi(a);
		if (cmp(b, val(0)) < 0)
			b = mi(b);
		return a.gcd(b);
	}
}


import java.io.*;
import java.util.*;

public class Solution {

	private StringTokenizer st;
	private BufferedReader in;
	private PrintWriter out;

	final static long mod = 1000000007;

	static class KQueue {
		long[] ar;
		int size = 0, p = 0;
		long sum = 0;

		KQueue(int k) {
			ar = new long[k];
		}

		void add(long x) {
			if (size == ar.length) {
				sum = (sum + mod - ar[p]) % mod;
			} else {
				size++;
			}
			ar[p] = x;
			sum = (sum + x) % mod;
			p = (p + 1) % ar.length;
		}

		long last() {
			return size < ar.length ? 0 : ar[p];
		}

		void clear() {
			sum = 0L;
			size = 0;
			p = 0;
		}

		@Override
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			for (int i = 0; i < size; ++i) {
				sb.append(ar[(p + i) % ar.length] + ",");
			}
			sb.append(":").append(sum);
			sb.append("]");
			return sb.toString();
		}
	}

	public void solve() throws IOException {
		int n = nextInt();
		int k = nextInt();
		String s = next();
		long ans = 0L;
		KQueue q1 = new KQueue(k);
		KQueue q2 = new KQueue(k);
		q1.add(1L);
		for (int i = 0; i < n; ++i) {
			if (s.charAt(i) == 'B') {
				long s1 = (q1.last() + q2.sum) % mod;
				q2.clear();
				q2.add(s1);
				q1.add(0L);
			} else if (s.charAt(i) == 'W') {
				ans = (ans + q2.last()) % mod;
				q2.add(0L);
				long s0 = q1.sum;
				q1.clear();
				q1.add(s0);
			} else {
				ans = (2 * ans + q2.last()) % mod;
				long s1 = (q1.last() + q2.sum) % mod;
				long s0 = q1.sum;
				q2.add(s1);
				q1.add(s0);
			}
//			System.err.println(q1 + " " + q2 + " " + ans);
		}
		out.println(ans);
	}

	public void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		eat("");

		solve();

		out.close();
	}

	void eat(String s) {
		st = new StringTokenizer(s);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	static boolean failed = false;

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		new Solution().run();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;

public class ProblemD {
    static long MOD = 1000000007;

    static long[] pow2;

    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        pow2 = new long[1000011];
        pow2[0] = 1;
        for (int i = 0 ; i < 1000010 ; i++) {
            pow2[i+1] = (pow2[i] * 2) % MOD;
        }

        String[] line = s.readLine().split(" ");
        int n = Integer.valueOf(line[0]);
        int k = Integer.valueOf(line[1]);
        char[] data = s.readLine().toCharArray();
        if (k * 2 > n) {
            out.println(0);
            out.flush();
            return;
        }

        int[] sumX = new int[n+1];
        int[] sumB = new int[n+1];
        int[] sumW = new int[n+1];
        for (int i = 0 ; i < n ; i++) {
            int dx = 0, db = 0, dw = 0;
            if (data[i] == 'X') {
                dx = 1;
            } else if (data[i] == 'W') {
                dw = 1;
            } else {
                db = 1;
            }
            sumX[i+1] = sumX[i] + dx;
            sumB[i+1] = sumB[i] + db;
            sumW[i+1] = sumW[i] + dw;
        }

        long[] nob = new long[n];
        for (int i = 0 ; i < n ; i++) {
            int mul = (data[i] == 'X') ? 2: 1;
            if (i >= 1) {
                nob[i] = (nob[i-1] * mul) % MOD;
            } else {
                nob[i] = mul;
            }
            if (i >= k-1) {
                if (sumW[i+1] - sumW[i-k+1] == 0) {
                    if (i == k-1 || data[i-k] != 'B') {
                        nob[i] -= (i > k) ? nob[i-k-1] : 1;
                        if (nob[i] < 0) {
                            nob[i] += MOD;
                        }
                    }
                }
            }
        }

        long[] now = new long[n];
        for (int i = n-1 ; i >= 0 ; i--) {
            int mul = (data[i] == 'X') ? 2 : 1;
            if (i < n-1) {
                now[i] = (now[i+1] * mul) % MOD;
            } else {
                now[i] = mul;
            }
            if (i <= n-k) {
                if (sumB[i+k] - sumB[i] == 0) {
                    if (i == n-k || data[i+k] != 'W') {
                        now[i] -= (i < n-k-1) ? now[i+k+1] : 1;
                        if (now[i] < 0) {
                            now[i] += MOD;
                        }
                    }
                }
            }
        }

        debug("done");
//      debug(nob);
//      debug(now);

        long answer = 0;
        for (int i = k ; i < n ; i++) {
            if (sumW[i] - sumW[i-k] == 0) {
                if (i >= k + 1 && data[i-k-1] == 'B') {
                    continue;
                }
                long beforeB = 1;
                if (i >= k + 2) {
                    beforeB *= nob[i-k-2];
                }

                long afterW = (pow2[sumX[n] - sumX[i]] - now[i]);
                if (afterW < 0) {
                    afterW += MOD;
                }

                answer += (beforeB * afterW) % MOD;
                answer %= MOD;
            }
        }

        out.println(answer);
        out.flush();
    }

    public static void debug(Object... os){
        System.err.println(Arrays.deepToString(os));
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;

public class ProblemD {
    static long MOD = 1000000007;

    static long[] pow2;

    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        pow2 = new long[1000011];
        pow2[0] = 1;
        for (int i = 0 ; i < 1000010 ; i++) {
            pow2[i+1] = (pow2[i] * 2) % MOD;
        }

        String[] line = s.readLine().split(" ");
        int n = Integer.valueOf(line[0]);
        int k = Integer.valueOf(line[1]);
        char[] data = s.readLine().toCharArray();
        if (k * 2 > n) {
            out.println(0);
            out.flush();
            return;
        }

        int[] sumX = new int[n+1];
        int[] sumB = new int[n+1];
        int[] sumW = new int[n+1];
        for (int i = 0 ; i < n ; i++) {
            int dx = 0, db = 0, dw = 0;
            if (data[i] == 'X') {
                dx = 1;
            } else if (data[i] == 'W') {
                dw = 1;
            } else {
                db = 1;
            }
            sumX[i+1] = sumX[i] + dx;
            sumB[i+1] = sumB[i] + db;
            sumW[i+1] = sumW[i] + dw;
        }

        long[] nob = new long[n];
        for (int i = 0 ; i < n ; i++) {
            int mul = (data[i] == 'X') ? 2: 1;
            if (i >= 1) {
                nob[i] = nob[i-1] * mul;
            } else {
                nob[i] = mul;
            }
            if (i >= k-1) {
                if (sumW[i+1] - sumW[i-k+1] == 0) {
                    if (i == k-1 || data[i-k] != 'B') {
                        nob[i] -= (i > k) ? nob[i-k-1] : 1;
                        while (nob[i] < 0) {
                            nob[i] += MOD;
                        }
                    }
                }
            }
        }

        long[] now = new long[n];
        for (int i = n-1 ; i >= 0 ; i--) {
            int mul = (data[i] == 'X') ? 2 : 1;
            if (i < n-1) {
                now[i] = now[i+1] * mul;
            } else {
                now[i] = mul;
            }
            if (i <= n-k) {
                if (sumB[i+k] - sumB[i] == 0) {
                    if (i == n-k || data[i+k] != 'W') {
                        now[i] -= (i < n-k-1) ? now[i+k+1] : 1;
                        while (now[i] < 0) {
                            now[i] += MOD;
                        }
                    }
                }
            }
        }

//      debug(nob);
//      debug(now);

        long answer = 0;
        for (int i = k ; i < n ; i++) {
            if (sumW[i] - sumW[i-k] == 0) {
                if (i >= k + 1 && data[i-k-1] == 'B') {
                    continue;
                }
                long beforeB = 1;
                if (i >= k + 2) {
                    beforeB *= nob[i-k-2];
                }

                long afterW = (pow2[sumX[n] - sumX[i]] - now[i]);
                if (afterW < 0) {
                    afterW += MOD;
                }

                answer += (beforeB * afterW) % MOD;
                answer %= MOD;
            }
        }

        out.println(answer);
        out.flush();
    }

    public static void debug(Object... os){
        System.err.println(Arrays.deepToString(os));
    }

}


//package round129;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), K = ni();
		int mod = 1000000007;
		char[] str = ns(n);

		int[] b = new int[n];
		{
			int[] dp = new int[n+1];
			dp[0] = 1;
			int sum = 1;
			int ep = 0;
			for(int i = 1;i <= n;i++){
				if(str[i-1] == 'B'){
				}else if(str[i-1] == 'W'){
					dp[i] = sum;
					for(int j = ep;j < i;j++){
						dp[j] = 0;
					}
					ep = i;
				}else{
					dp[i] = sum;
					sum = sum * 2 % mod;
				}
				if(i-K >= 0){
					b[i-1] = dp[i-K];
					sum = (sum + mod - dp[i-K]) % mod;
					dp[i-K] = 0;
				}
			}
		}

		int[] w = new int[n];
		{
			int[] dp = new int[n+1];
			dp[0] = 1;
			int sum = 1;
			int ep = 0;
			for(int i = 1;i <= n;i++){
				if(str[n-i] == 'W'){
				}else if(str[n-i] == 'B'){
					dp[i] = sum;
					for(int j = ep;j < i;j++){
						dp[j] = 0;
					}
					ep = i;
				}else{
					dp[i] = sum;
					sum = sum * 2 % mod;
				}
				if(i-K >= 0){
					w[n-i] = dp[i-K];
					sum = (sum + mod - dp[i-K]) % mod;
					dp[i-K] = 0;
				}
			}
		}

		int[] ws = new int[n+1];
		for(int i = n-1;i >= 0;i--){
			ws[i] = (ws[i+1] + w[i]) % mod;
		}

		long im = inv(2, mod);
		long[] tf = new long[n+1];
		long[] tb = new long[n+1];
		int two = 1;
		tf[0] = 1;
		tb[n] = 1;
		for(int i = 0;i < n;i++){
			tf[i+1] = str[i] == 'X' ? tf[i] * im % mod : tf[i];
			tb[n-1-i] = str[n-1-i] == 'X' ? tb[n-i] * im % mod : tb[n-i];
			if(str[i] == 'X')two = two * 2 % mod;
		}
		long wsum = 0;
		for(int i = 0;i < n;i++){
			b[i] = (int)(b[i] * tf[i+1] % mod);
			w[i] = (int)(w[i] * tb[i] % mod);
			wsum += w[i];
		}
		wsum %= mod;

		long ret = 0;
		for(int i = 0;i < n;i++){
			wsum = (wsum + mod - w[i]) % mod;
			ret += wsum * b[i] % mod * two % mod;
		}
		out.println(ret % mod);
	}

	public static long inv(long a, int p)
	{
		long ret = 1;
		long mul = a;
		for(long n = p-2;n > 0;n >>>= 1){
			if((n&1)==1)ret = ret * mul % p;
			mul = mul * mul % p;
		}
		return ret;
	}

	void run() throws Exception
	{
//		int n = 1000000;
//		Random gen = new Random();
//		int K = gen.nextInt(10)+1;
//		StringBuilder sb = new StringBuilder();
//		sb.append(n + " ");
//		sb.append(K + " ");
//		for(int i = 0;i < n;i++){
//			sb.append("XBW".charAt(gen.nextInt(3)));
//		}
//		INPUT = sb.toString();

		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new D().run();
	}

	public int ni()
	{
		try {
			int num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public long nl()
	{
		try {
			long num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public String ns()
	{
		try{
			int b = 0;
			StringBuilder sb = new StringBuilder();
			while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
			if(b == -1)return "";
			sb.append((char)b);
			while(true){
				b = is.read();
				if(b == -1)return sb.toString();
				if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
				sb.append((char)b);
			}
		} catch (IOException e) {
		}
		return "";
	}

	public char[] ns(int n)
	{
		char[] buf = new char[n];
		try{
			int b = 0, p = 0;
			while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
			if(b == -1)return null;
			buf[p++] = (char)b;
			while(p < n){
				b = is.read();
				if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
				buf[p++] = (char)b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}

	double nd() { return Double.parseDouble(ns()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			while(ranans0 < 0);
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
			while(ranansb < 0);
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
			while(ranans0 < 0);
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
			while(ranansb < 0);
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			while(ranans0 < 0) ranans0 += mod;
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
//			while(ranansb < 0);
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
//			while(ranans0 < 0);
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
//			while(ranansb < 0);
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
int dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			while(ranans0 < 0);
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
//			while(ranansb < 0);
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
//			while(ranans0 < 0);
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
//			while(ranansb < 0);
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const long long mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		while(ans0 < 0);
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			while(ranans0 < 0) ranans0 += mod;
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
//			while(ranansb < 0);
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
//			while(ranans0 < 0);
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
//			while(ranansb < 0);
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			while(ranans0 < 0);
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
			while(ranansb < 0);
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
//			while(ranans0 < 0);
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
//			while(ranansb < 0);
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
int dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
			ans *= 2;
			ans += temp1;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
			ans += temp1;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const long long mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
//		while(ans0 < 0);
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			while(ranans0 < 0) ranans0 += mod;
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
			while(ranansb < 0) ranansb += mod;
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
			while(ranans0 < 0) ranans0 += mod;
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
			while(ranansb < 0) ranansb += mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
//			while(ranans0 < 0);
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
//			while(ranansb < 0);
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
//			while(ranans0 < 0);
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
//			while(ranansb < 0);
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


/*
 * d.cpp
 *
 *  Created on: 2012-7-13
 *      Author: Administrator
 */
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

const long long mod = 1000000007;
const int maxn = 2000000;
int l, lsub;
char str[maxn + 1];
long long  dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0;

int main(){
//	freopen("input.txt", "r", stdin);
	#define int long long
	scanf("%d%d", &l, &lsub);
	scanf("%s", str);

	now = -1; nob = -1;
/*	if(str[0] == 'W') dpw[0] = 1;
	if(str[0] == 'B') dpb[0] = 1;
	else dpw[0] = dpb[0] = 1;*/
	for(int i = 0; i < l; i++)
	ans0 = 1;
	for(int i = 0; i < l; i++){
//		while(ans0 < 0);
		if(str[i] == 'X'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			ranans0 = ans0 * 2 - temp;
			while(ranans0 < 0) ranans0 += mod;
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			ranansb = ansb * 2 + temp - temp1;
			while(ranansb < 0) ranansb += mod;
			ans *= 2;
			ans %= mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'B'){
			int temp = 0;
			if(i - now >= lsub){
				temp = 1;
				if(i >= lsub) temp = dpw[i - lsub];
			}
			nob = i;
			ranans0 = ans0 - temp;
			while(ranans0 < 0) ranans0 += mod;
			ranansb = ansb + temp;
			dpw[i] = 0;
			dpb[i] = (ansb + temp) % mod;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
		if(str[i] == 'W'){
			int temp1 = 0;
			if(i - nob >= lsub){
				if(i >= lsub) temp1 = dpb[i - lsub];
			}
			now = i;
			ranans0 = ans0;
			ranansb = ansb - temp1;
			while(ranansb < 0) ranansb += mod;
			ans += temp1;
			ans %= mod;
			dpw[i] = ans0 % mod;
			dpb[i] = 0;
			ans0 = ranans0 % mod;
			ansb = ranansb % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


#include<stdio.h>
#define MAXN 1000003
#define MOD 1000000007
int n,m;
char s[MAXN];
long long nob[MAXN];
long long cnob[MAXN];
long long now[MAXN];
long long cnow[MAXN];
long long dp[MAXN];
int lw[MAXN];
int lb[MAXN];
/*long long query(long long *f,int a,int b){
	long long res = 0;
	res += f[b];
	if( a != 0 ) res -= f[a-1];
	return res;
}*/
int md(long long &x){
	x %= MOD;
	if( x < 0 ) x += MOD;
}
int main(){
	scanf("%d %d",&n,&m);
	scanf("%s",s);
	for(int i = 0 ;i < n ;i ++ ){
		if( s[i] == 'B' ) s[i] = 1;
		else if( s[i] == 'W' ) s[i] = 0;
		else s[i] = 2;
	}

	int pos = -1;
	for(int i = 0 ;i < n; i++ ){
		if( s[i] == 0 ) pos = i;
		lw[i] = pos;
	}

	if( s[0] == 2 || s[0] == 0 ){
		nob[0] = 1;
		cnob[0] = 1;
	}

	for(int k = 1 ;k < n ;k++ ){
		if( s[k] == 0 || s[k] == 2 ){
			int l = k-m;
			if( l < 0 ) l = 0 ;
			if( lw[k-1] > l ) l = lw[k-1];
			long long res = 0 ;
			res += cnob[k-1];
			if( l > 0 ) res -= cnob[l-1];
			if( lw[k-1] == -1 && k-m < 0 ) res++;
			nob[k] = res;
			md(nob[k]);
		}
		cnob[k] = nob[k] + cnob[k-1];
		md(cnob[k]);
	}
	//for(int i =0 ;i < n ; i++ ) printf("%I64d ",nob[i]);
	//printf("\n");

	for(int i = n-1 ; i >= m ; i-- ){
		if( lw[i] == -1 || lw[i] <= i-m )
			nob[i] = nob[i-m];
		else
			nob[i] = 0;
	}
	if( lw[m-1] == -1 ) nob[m-1] = 1;
	else nob[m-1] = 0;
	for(int i = 0 ;i < m-1 ; i++ ) nob[i] = 0;
	//for(int i =0 ;i < n ; i++ ) printf("%I64d ",nob[i]);
	//printf("\n");

	pos = -1 ;
	for(int i = n-1 ; i>= 0 ; i-- ){
		if( s[i] == 1 ) pos = i;
		lb[i] = pos;
	}
	if( s[n-1] == 2 || s[n-1] == 1 ){
		now[n-1] = 1;
		cnow[n-1] = 1;
	}
	for(int k = n-2 ; k >= 0 ; k-- ){
		if( s[k] == 1 || s[k] == 2 ){
			int l = k+m;
			if( l >= n ) l = n-1;
			if( lb[k+1] != -1 && lb[k+1] < l ) l = lb[k+1];
			long long res = 0;
			res += cnow[k+1];
			if( l < n-1 ) res -= cnow[l+1];
			if( lb[k+1] == -1 && k+m >= n ) res++;
			now[k] = res;
			md(now[k]);
			//printf("%d - %I64d %d\n",k,res,l);
		}
		cnow[k] = now[k] + cnow[k+1];
		md(cnow[k]);
	}

	//for(int i =0 ;i < n ;i++ ) printf("%I64d ",now[i]);
	//printf("\n");
	for(int i = 0 ;i <= n-m-1 ; i++ ){
		if( lb[i] == -1 || lb[i] >= i+m ){
			now[i] = now[i+m];
		}
		else now[i] = 0;
	}
	if( lb[n-m] == -1 ) now[n-m] = 1;
	else now[n-m] = 0;
	for(int i = n-m+1 ; i < n ;i++ ) now[i] = 0;

//	for(int i =0 ;i < n ;i++ ) printf("%I64d ",now[i]);
//	printf("\n");
	long long cum = 0;
	for(int i = n-m ; i >= 0 ; i-- ){
		if( s[i] == 2 ) cum *= 2;
		cum += now[i] ;
		md(cum);
		dp[i] = cum;
	}
	//for(int i = 0;i < n ; i++ ) printf("%I64d ",dp[i]);
	//printf("\n");
	long long ans = 0;
	for(int i = m-1 ; i < n-m ;i++ ){
		ans += nob[i]*dp[i+1];
		md(ans);
	}
	printf("%I64d\n",ans);
}


#include<stdio.h>
#define MAXN 1000003
#define MOD 1000000007
int n,m;
char s[MAXN];
long long nob[MAXN];
long long cnob[MAXN];
long long now[MAXN];
long long cnow[MAXN];
long long dp[MAXN];
int lw[MAXN];
int lb[MAXN];
/*long long query(long long *f,int a,int b){
	long long res = 0;
	res += f[b];
	if( a != 0 ) res -= f[a-1];
	return res;
}*/
int md(long long &x){
	x %= MOD;
	if( x < 0 ) x += MOD;
}
int main(){
	scanf("%d %d",&n,&m);
	scanf("%s",s);
	for(int i = 0 ;i < n ;i ++ ){
		if( s[i] == 'B' ) s[i] = 1;
		else if( s[i] == 'W' ) s[i] = 0;
		else s[i] = 2;
	}

	int pos = -1;
	for(int i = 0 ;i < n; i++ ){
		if( s[i] == 0 ) pos = i;
		lw[i] = pos;
	}

	if( s[0] == 2 || s[0] == 0 ){
		nob[0] = 1;
		cnob[0] = 1;
	}

	for(int k = 1 ;k < n ;k++ ){
		if( s[k] == 0 || s[k] == 2 ){
			int l = k-m;
			if( l < 0 ) l = 0 ;
			if( lw[k-1] > l ) l = lw[k-1];
			long long res = 0 ;
			res += cnob[k-1];
			if( l > 0 ) res -= cnob[l-1];
			if( lw[k-1] == -1 && k-m < 0 ) res++;
			nob[k] = res;
			md(nob[k]);
		}
		cnob[k] = nob[k] + cnob[k-1];
		md(cnob[k]);
	}
	//for(int i =0 ;i < n ; i++ ) printf("%I64d ",nob[i]);
	//printf("\n");

	for(int i = n-1 ; i >= m ; i-- ){
		if( lw[i] == -1 || lw[i] <= i-m )
			nob[i] = nob[i-m];
		else
			nob[i] = 0;
	}
	if( lw[m-1] == -1 ) nob[m-1] = 1;
	for(int i = 0 ;i < m-1 ; i++ ) nob[i] = 0;
	//for(int i =0 ;i < n ; i++ ) printf("%I64d ",nob[i]);
	//printf("\n");

	pos = -1 ;
	for(int i = n-1 ; i>= 0 ; i-- ){
		if( s[i] == 1 ) pos = i;
		lb[i] = pos;
	}
	if( s[n-1] == 2 || s[n-1] == 1 ){
		now[n-1] = 1;
		cnow[n-1] = 1;
	}
	for(int k = n-2 ; k >= 0 ; k-- ){
		if( s[k] == 1 || s[k] == 2 ){
			int l = k+m;
			if( l >= n ) l = n-1;
			if( lb[k+1] != -1 && lb[k+1] < l ) l = lb[k+1];
			long long res = 0;
			res += cnow[k+1];
			if( l < n-1 ) res -= cnow[l+1];
			if( lb[k+1] == -1 && k+m >= n ) res++;
			now[k] = res;
			md(now[k]);
			//printf("%d - %I64d %d\n",k,res,l);
		}
		cnow[k] = now[k] + cnow[k+1];
		md(cnow[k]);
	}

	//for(int i =0 ;i < n ;i++ ) printf("%I64d ",now[i]);
	//printf("\n");
	for(int i = 0 ;i <= n-m-1 ; i++ ){
		if( lb[i] == -1 || lb[i] >= i+m ){
			now[i] = now[i+m];
		}
		else now[i] = 0;
	}
	if( lb[n-m] == -1 ) now[n-m] = 1;
	for(int i = n-m+1 ; i < n ;i++ ) now[i] = 0;

//	for(int i =0 ;i < n ;i++ ) printf("%I64d ",now[i]);
//	printf("\n");
	long long cum = 0;
	for(int i = n-m ; i >= 0 ; i-- ){
		if( s[i] == 2 ) cum *= 2;
		cum += now[i] ;
		md(cum);
		dp[i] = cum;
	}
	//for(int i = 0;i < n ; i++ ) printf("%I64d ",dp[i]);
	//printf("\n");
	long long ans = 0;
	for(int i = m-1 ; i < n-m ;i++ ){
		ans += nob[i]*dp[i+1];
		md(ans);
	}
	printf("%I64d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 1000010
#define mod 1000000007
using namespace std;
typedef long long LL;
char str[maxn];
int n,k;
pair<LL,LL> ex_gcd(LL a,LL b)
{
	if(b==0)
		return make_pair(1,0);
	pair<LL,LL> temp=ex_gcd(b,a%b);
	return make_pair(temp.second,temp.first-a/b*temp.second);
}
LL Dp()
{
	static int sum[maxn][3];
	static LL F[maxn][2],power[maxn],anti[maxn];
	for(int i=1;i<=n;++i)
	{
		sum[i][0]=sum[i-1][0],sum[i][1]=sum[i-1][1],sum[i][2]=sum[i-1][2];
		if(str[i]=='B')
			++sum[i][0];
		else if(str[i]=='W')
			++sum[i][1];
		else
			++sum[i][2];
	}
	power[0]=1,anti[0]=1;
	for(int i=1;i<=n;++i)
	{
		power[i]=power[i-1]*2%mod;
		anti[i]=ex_gcd(power[i],mod).first;
		if(anti[i]<0)
			anti[i]+=mod;
	}
	for(int i=k;i<=n;++i)
		if(sum[i][1]-sum[i-k][1]==0)
			F[i][0]=power[sum[i-k][2]];
	LL sum1,sum2,ans=0;
	sum1=0,sum2=0;
	for(int i=1;i<=k;++i)
		sum2=(sum2+F[i][0])%mod;
	for(int i=k+1;i<=n;++i)
	{
		F[i][0]=(F[i][0]-sum1-sum2+mod+mod)%mod;
		if(sum[i][1]-sum[i-k][1]!=0)
			F[i][0]=0;
		sum2=(sum2-F[i-k][0]+F[i][0]+mod)%mod;
		sum1=(sum1+F[i-k][0])%mod;
		if(str[i-k+1]=='X')
			sum1=sum1*2%mod;
	}
	for(int i=n-k+1;i>=1;--i)
		if(sum[i+k-1][0]-sum[i-1][0]==0)
			F[i][1]=power[sum[n][2]-sum[i+k-1][2]];
	sum1=0,sum2=0;
	for(int i=n;i>=n-k+1;--i)
		sum2=(sum2+F[i][1])%mod;
	for(int i=n-k;i>=1;--i)
	{
		F[i][1]=(F[i][1]-sum1-sum2+mod+mod)%mod;
		if(sum[i+k-1][0]-sum[i-1][0]!=0)
			F[i][1]=0;
		sum2=(sum2-F[i+k][1]+F[i][1]+mod)%mod;
		sum1=(sum1+F[i+k][1])%mod;
		if(str[i+k-1]=='X')
			sum1=sum1*2%mod;
	}
	sum1=F[1][0]*anti[sum[1][2]]%mod;
	for(int i=2;i<=n;++i)
	{
		ans=(ans+F[i][1]*power[sum[i-1][2]]%mod*sum1)%mod;
		sum1=(sum1+F[i][0]*anti[sum[i][2]])%mod;
	}
	return ans;
}
int main()
{
	scanf("%d %d %s",&n,&k,str+1);
	cout<<Dp()<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<limits>

using namespace std;

typedef long long LL;
const int max_n=1000000;
const LL modref=1000000007;

int n,k;
char s[max_n+10];

int xct[max_n+1];
int bct[max_n+1];
int wct[max_n+1];

LL pref[max_n+1];
LL suff[max_n+1];

LL e2(int k)
{
	if(k==0)
		return ((LL)(1));
	else
	{
		LL t=e2(k/2);
		return ( t*t*( (k%2==1) ? ((LL)(2)) : ((LL)(1)) ) )%modref;
	}
}

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

	xct[0]=0; bct[0]=0; wct[0]=0;
	for(int i=1; i<=n; ++i)
	{
		xct[i]=xct[i-1]+(s[i-1]=='X'?1:0);
		bct[i]=bct[i-1]+(s[i-1]=='B'?1:0);
		wct[i]=wct[i-1]+(s[i-1]=='W'?1:0);
	}

	pref[0]=1;
	for(int i=1; i<=n; ++i)
	{
		pref[i]=pref[i-1]*(s[i-1]=='X'?((LL)(2)):((LL)(1)));
		pref[i]%=modref;
		if(i==k and (wct[i]==wct[i-k]))
		{
			pref[i]+=(modref-pref[i-k]);
			pref[i]%=modref;
		}
		if(i>k and (wct[i]==wct[i-k]) and s[i-k-1]!='B')
		{
			pref[i]+=(modref-pref[i-k-1]);
			pref[i]%=modref;
		}
		//cout<<i<<" "<<pref[i]<<endl;
	}

	suff[n]=1;
	for(int i=n-1; i>=0; --i)
	{
		suff[i]=suff[i+1]*(s[i]=='X'?((LL)(2)):((LL)(1)));
		suff[i]%=modref;
		if(i==n-k and (bct[i]==bct[i+k]))
		{
			suff[i]+=(modref-suff[i+k]);
			suff[i]%=modref;
		}
		if(i<n-k and (bct[i]==bct[i+k]) and s[i+k]!='W')
		{
			suff[i]+=(modref-suff[i+k+1]);
			suff[i]%=modref;
		}
	}

	LL res=0;
	for(int i=k; i<=n-k; ++i)
	{
		if(i==k and wct[i]==wct[i-k])
		{
			res+=pref[i-k]*(e2(xct[n]-xct[i])+modref-suff[i]);
			res%=modref;
		}
		if(i>k and wct[i]==wct[i-k] and s[i-k-1]!='B')
		{
			res+=pref[i-k-1]*(e2(xct[n]-xct[i])+modref-suff[i]);
			res%=modref;
		}
	}

	cout<<res<<endl;

	return 0;
}


100 3

XXXXXWXXXXBXXWXXBXXBXXXXXXXXXXXXXXXXWWXXWXXWXXXXWWXXXXXWXXXXBWXXXXWXBXXXWXXXBWXXWXXXWXXXXWWWXXXXXWXX


#include<iostream>
#include<cstdio>
#include<limits>

using namespace std;

typedef long long LL;
const int max_n=1000000;
const LL modref=1000000007;

int n,k;
char s[max_n+10];

int xct[max_n+1];
int bct[max_n+1];
int wct[max_n+1];

LL pref[max_n+1];
LL suff[max_n+1];

LL e2(int k)
{
	if(k==0)
		return ((LL)(1));
	else
	{
		int t=e2(k/2);
		return ( t*t*( (k%2==1) ? ((LL)(2)) : ((LL)(1)) ) )%modref;
	}
}

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

	xct[0]=0; bct[0]=0; wct[0]=0;
	for(int i=1; i<=n; ++i)
	{
		xct[i]=xct[i-1]+(s[i-1]=='X'?1:0);
		bct[i]=bct[i-1]+(s[i-1]=='B'?1:0);
		wct[i]=wct[i-1]+(s[i-1]=='W'?1:0);
	}

	pref[0]=1;
	for(int i=1; i<=n; ++i)
	{
		pref[i]=pref[i-1]*(s[i-1]=='X'?((LL)(2)):((LL)(1)));
		pref[i]%=modref;
		if(i==k and (wct[i]==wct[i-k]))
		{
			pref[i]+=(modref-pref[i-k]);
			pref[i]%=modref;
		}
		if(i>k and (wct[i]==wct[i-k]) and s[i-k-1]!='B')
		{
			pref[i]+=(modref-pref[i-k-1]);
			pref[i]%=modref;
		}
		//cout<<i<<" "<<pref[i]<<endl;
	}

	suff[n]=1;
	for(int i=n-1; i>=0; --i)
	{
		suff[i]=suff[i+1]*(s[i]=='X'?((LL)(2)):((LL)(1)));
		suff[i]%=modref;
		if(i==n-k and (bct[i]==bct[i+k]))
		{
			suff[i]+=(modref-suff[i+k]);
			suff[i]%=modref;
		}
		if(i<n-k and (bct[i]==bct[i+k]) and s[i+k]!='W')
		{
			suff[i]+=(modref-suff[i+k+1]);
			suff[i]%=modref;
		}
	}

	LL res=0;
	for(int i=k; i<=n-k; ++i)
	{
		if(i==k and wct[i]==wct[i-k])
		{
			res+=pref[i-k]*(e2(xct[n]-xct[i])+modref-suff[i]);
			res%=modref;
		}
		if(i>k and wct[i]==wct[i-k] and s[i-k-1]!='B')
		{
			res+=pref[i-k-1]*(e2(xct[n]-xct[i])+modref-suff[i]);
			res%=modref;
		}
	}

	cout<<res<<endl;

	return 0;
}


#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define mo 1000000007
#define N 1000010
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,an;
int f[N],g[N],a[N];
char p[N];
inline void work(int ty) {
	int last=0,s=1;
	g[0]=1;
	For(i,1,n) {
		g[i]=0;
		for (;last+m<i;last++) s=(s-g[last])%mo;
		if (p[i]=='W') {
			g[i]=s;
			s=g[i];
			last=i;
		} else if (p[i]=='X') {
			g[i]=s;
			s=(s+g[i])%mo;
		}
	}
	last=0;
	For(i,1,n) {
		f[i]=0;
		if (p[i]=='W') last=i;
		else if (last+m<=i) f[i]=g[i-m];
	}
	if (!ty) {
		For(i,1,n) {
			f[i]=(f[i]+f[i-1])%mo;
			if (p[i]=='X') f[i]=(f[i]+f[i-1])%mo;
		}
		For(i,0,n) a[i]=f[i];
	} else For(i,1,n) an=(1ll*f[i]*a[n-i]+an)%mo;
}
int main() {
	scanf("%d%d",&n,&m);
	scanf("%s",p+1);
	work(0);
	For(i,1,n/2) swap(p[i],p[n-i+1]);
	For(i,1,n) if (p[i]=='W') p[i]='B';
		else if (p[i]=='B') p[i]='W';
	work(1);
	printf("%d\n",an);
	//for(;;);
	return 0;
}


#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define mo 1000000007
#define N 1000010
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,an;
int f[N],g[N],a[N];
char p[N];
inline void work(int ty) {
	int last=0,s=1;
	g[0]=1;
	For(i,1,n) {
		g[i]=0;
		for (;last+m<i;last++) s=(s-g[last])%mo;
		if (p[i]=='W') {
			g[i]=s;
			s=g[i];
			last=i;
		} else if (p[i]=='X') {
			g[i]=s;
			s=(s+g[i])%mo;
		}
	}
	last=0;
	For(i,1,n) {
		f[i]=0;
		if (p[i]=='W') last=i;
		else if (last+m<=i) f[i]=g[i-m];
	}
	if (!ty) {
		For(i,1,n) {
			f[i]=(f[i]+f[i-1])%mo;
			if (p[i]=='X') f[i]=(f[i]+f[i-1])%mo;
		}
		For(i,0,n) a[i]=f[i];
	} else For(i,1,n) an=(1ll*f[i]*a[n-i]+an)%mo;
}
int main() {
	scanf("%d%d",&n,&m);
	scanf("%s",p+1);
	work(0);
	For(i,1,n/2) swap(p[i],p[n-i+1]);
	For(i,1,n) if (p[i]=='W') p[i]='B';
		else if (p[i]=='B') p[i]='W';
	work(1);
	if (an<0) an+=mo;
	printf("%d\n",an);
	//for(;;);
	return 0;
}