#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios_base::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll GCD(ll a, ll b) { return !b ? a : GCD(b , a % b); }
ll LCM(ll x, ll y) { return (x * y / GCD(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
//bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 3 && j < 3; }
//int dx[] = { 1, 0, -1, 0 };
//int dy[] = { 0, 1, 0, -1 };
//int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
//int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
int n;
string s1;
string IntToString (int a){
    stringstream temp;
    temp << a;
    return temp.str();
}
int main(){
	Abdulrahman
	cin >> n;
	for(int i = 0 ; i < n ; ++i){
        string s = IntToString(i);
        s1 += s;
	}
	if( n % 2 == 0) return cout << -1 << endl , 0;
	for(int i = 0 ; i < n ; ++i)    cout << s1[i] << (i == n-1 ? " \n" : " ");
    for(int i = 0 ; i < n ; ++i)    cout << s1[i] << (i == n-1 ? " \n" : " ");
	for(int i = 0 ; i < n ; ++i)    cout <<  (s1[i] - '0' + s1[i] - '0' ) % n << " " ;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios_base::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll GCD(ll a, ll b) { return !b ? a : GCD(b , a % b); }
ll LCM(ll x, ll y) { return (x * y / GCD(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
//bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 3 && j < 3; }
//int dx[] = { 1, 0, -1, 0 };
//int dy[] = { 0, 1, 0, -1 };
//int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
//int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
int n ;
int main(){
	scanf("%d" , &n);
	if( n % 2 == 0) return printf("%d\n" , -1) , 0; // even
	for(int i = 0 ; i < n ; ++i)   printf("%d " , i);
    puts("");
    for(int i = 0 ; i < n ; ++i)   printf("%d " , i);
    puts("");
	for(int i = 0 ; i < n ; ++i)   printf("%d " , (i * 2) % n  );
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios_base::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll GCD(ll a, ll b) { return !b ? a : GCD(b , a % b); }
ll LCM(ll x, ll y) { return (x * y / GCD(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
//bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 3 && j < 3; }
//int dx[] = { 1, 0, -1, 0 };
//int dy[] = { 0, 1, 0, -1 };
//int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
//int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
int n ];
int main(){
	scanf("%d" , &n);
	if( n % 2 == 0) return printf("%d\n" , -1) , 0; // even
	for(int i = 0 ; i < n ; ++i)   printf("%d " , i);
    puts("");
    for(int i = 0 ; i < n ; ++i)   printf("%d " , i);
    puts("");
	for(int i = 0 ; i < n ; ++i)   printf("%d " , (i * 2) % n  );
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios_base::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll GCD(ll a, ll b) { return !b ? a : GCD(b , a % b); }
ll LCM(ll x, ll y) { return (x * y / GCD(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
//bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 3 && j < 3; }
//int dx[] = { 1, 0, -1, 0 };
//int dy[] = { 0, 1, 0, -1 };
//int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
//int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
int n , A[N];
int main(){
	Abdulrahman
	cin >> n;
	if( n % 2 == 0) return cout << -1 << endl , 0; // even
	for(int i = 0 ; i < n ; ++i)    A[i] = i;
	for(int i = 0 ; i < n ; ++i)    cout << A[i] << (i == n-1 ? " \n" : " ");
    for(int i = 0 ; i < n ; ++i)    cout << A[i] << (i == n-1 ? " \n" : " ");
	for(int i = 0 ; i < n ; ++i)    cout << (A[i]  + A[i] ) % n << " " ;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios_base::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll GCD(ll a, ll b) { return !b ? a : GCD(b , a % b); }
ll LCM(ll x, ll y) { return (x * y / GCD(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
//bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 3 && j < 3; }
//int dx[] = { 1, 0, -1, 0 };
//int dy[] = { 0, 1, 0, -1 };
//int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
//int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
int n , A[N];
int main(){
	scanf("%d" , &n);
	if( n % 2 == 0) return printf("%d\n" , -1) , 0; // even
	for(int i = 0 ; i < n ; ++i)    A[i] = i;
	for(int i = 0 ; i < n ; ++i)   printf("%d " , A[i]);
    puts("");
    for(int i = 0 ; i < n ; ++i)   printf("%d " , A[i]);
    puts("");
	for(int i = 0 ; i < n ; ++i)   printf("%d " , (A[i] * 2) % n  );
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i=a;i>b;i--)
#define ri(x) scanf("%d", &x);
#define rl(x) scanf("%lld", &x)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
const int INF = 2e6;
const ll LINF = 8e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-9;

int n;

int main(){
    ri(n);
    if(n==2){
        printf("-1");
        return 0;
    }
    FOR(i, 0, n) printf("%d ", i);
    printf("\n");
    for(int i = 1;i < 2*n +1; i +=2 ) printf("%d ", (n - i)<0?2*n - i: n - i );
    printf("\n");
    FORR(i, n-1, -1) printf("%d ", i);
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i=a;i>b;i--)
#define ri(x) scanf("%d", &x);
#define rl(x) scanf("%lld", &x)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
const int INF = 2e6;
const ll LINF = 8e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-9;

int n;

int main(){
    ri(n);
    if(n%2 == 0){
        printf("-1");
        return 0;
    }
    FOR(i, 0, n) printf("%d ", i);
    printf("\n");
    for(int i = 1;i < 2*n +1; i +=2 ) printf("%d ", (n - i)<0?2*n - i: n - i );
    printf("\n");
    FORR(i, n-1, -1) printf("%d ", i);
    return 0;
}


#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <string.h>
#define ll unsigned long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;

int n;

int main(){
    ri(n);
    if(n%2==0){
        printf("-1");
        return 0;
    }
    FOR(i,0, n)
        printf("%d ", i);
    printf("\n");
    FOR(i, 0, n)
        printf("%d ", i);
    printf("\n");
    FOR(i, 0, n)
        printf("%d ", (i+i)%n);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NIL 0
#define INF 1e18
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pb push_back
#define F first
#define S second
#define pp pair<int,int>
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rpk(i,k,n) for(int i=k;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define RPK(i,k,n) for(int i=k;i<=n;i++)
#define ritr(i,gr) for(auto i=gr.begin();i!=gr.end();i++)

const int M = 1e9+7;

int V, E, i, j, k, u, v, x, y, p, q, r, t, n;
vi *g;
vb sn;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    if(n&1) {
        rep(i,n) {cout<<i<<" ";}
        cout<<"\n";
        rep(i,n) {cout<<n-i-1<< " ";}
        cout<<"\n";
        k = 1;
        j= n;
        while(j--) {
            cout<<k%n<<" ";
            k+=2;
        }
    }

    else {
        cout<<-1<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NIL 0
#define INF 1e18
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pb push_back
#define F first
#define S second
#define pp pair<int,int>
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rpk(i,k,n) for(int i=k;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define RPK(i,k,n) for(int i=k;i<=n;i++)
#define ritr(i,gr) for(auto i=gr.begin();i!=gr.end();i++)

const int M = 1e9+7;

int V, E, i, j, k, u, v, x, y, p, q, r, t, n;
vi *g;
vb sn;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    if(n&1) {
        k = 1;
        j= n;
        while(j--) {
            cout<<k%n<<" ";
            k+=2;
        }
        cout<<"\n";
        rep(i,n) {cout<<n-i-1<< " ";}
        cout<<"\n";
        rep(i,n) {cout<<i<<" ";}
        cout<<"\n";

    }

    else {
        cout<<-1<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define SS stringstream
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define ff first
#define ss second
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define OO 1e9
#define pi 3.141592654
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int arr[100001];
int main()
{
fast
memset(arr,0, sizeof(arr));

vector<int> per1,per2,per3;
int n;
cin>>n;

    bool ok=true;
    for (int i = 0,j=1; ok&&i<n;j++,i++){ok=false;
   if(i==n-1)
   {
       if(arr[(i%n)]==0){
           ok=true;
       per1.push_back(i);
       per2.push_back((0));
       per3.push_back((i%n));}

   } else if(arr[(i+j%n)]==0) {
       arr[(i+j%n)]=1;
       per1.push_back(i);
       per2.push_back(j);
       per3.push_back(((j+i)%n));
       ok=true;

   }
    }
    if(!ok)
    {
        cout<<-1;
        return 0;
    }
    for (int i = 0; i < per1.size() ; ++i)
        cout<<per1[i]<<" ";
    cout<<'\n';
    for (int i = 0; i < per2.size() ; ++i)
        cout<<per2[i]<<" ";
    cout<<'\n';
    for (int i = 0; i < per3.size() ; ++i)
        cout<<per3[i]<<" ";
    cout<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define SS stringstream
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define ff first
#define ss second
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define OO 1e9
#define pi 3.141592654
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int arr[100001];
int main()
{
fast
memset(arr,0, sizeof(arr));

vector<int> per1,per2,per3;
int n;
cin>>n;

    bool ok=true;
    for (int i = 0,j=1; ok&&i<n;j++,i++){ok=false;
   if(i==n-1)
   {
       if(arr[(i%n)]==0){
           ok=true;
       per1.push_back(i);
       per2.push_back((0));
       per3.push_back((i%n));}

   } else if(arr[(i+j%n)]==0) {
       arr[(i+j%n)]=1;
       per1.push_back(i);
       per2.push_back(j);
       per3.push_back((j+i%n));
       ok=true;

   }
    }
    if(!ok)
    {
        cout<<-1;
        return 0;
    }
    for (int i = 0; i < per1.size() ; ++i)
        cout<<per1[i]<<" ";
    cout<<'\n';
    for (int i = 0; i < per2.size() ; ++i)
        cout<<per2[i]<<" ";
    cout<<'\n';
    for (int i = 0; i < per3.size() ; ++i)
        cout<<per3[i]<<" ";
    cout<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define SS stringstream
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define ff first
#define ss second
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define OO 1e9
#define pi 3.141592654
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int arr[200004];
bool is[200001];
int main()
{
fast
    memset(arr,0, sizeof(arr));
memset(is,false, sizeof(is));
vector<int> per1,per2,per3;
int n;
cin>>n;
if(n==2)
{
    cout<<-1;
    return 0;
}
    for (int i = 0; i < n; ++i) {
        if(i>0)
            per1.push_back(i);
    }
per1.push_back(0);
    bool ok=true;
    for (int i = 0; ok&&i<n;i++){ok=false;
    for (int j = 0; j < n; ++j) {
        int tmp=(per1[i]+j)%n;
        if(is[j]==false&&arr[tmp]==0&&j>0||i==n-1&&j==0)
        {
            per2.push_back(j);
            per3.push_back(tmp);
            ok=true;
            arr[tmp]=1;
            is[j]=true;
            break;
        }
    }}
    if(!ok)
    {
        cout<<-1;
        return 0;
    }
    for (int i = 0; i < n ; ++i)
        cout<<per1[i]<<" ";
    cout<<'\n';
    for (int i = 0; i < n ; ++i)
        cout<<per2[i]<<" ";
    cout<<'\n';
    for (int i = 0; i < n ; ++i)
        cout<<per3[i]<<" ";
    cout<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define SS stringstream
#define all(x) x.begin(),x.end()
#define EPS 1e-9
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define ff first
#define ss second
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define OO 1e9
#define pi 3.141592654
#define fast std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int arr[200004];
int main()
{
fast
memset(arr,0, sizeof(arr));

vector<int> per1,per2,per3;
int n;
cin>>n;

    bool ok=true;
    for (int i = 0,j=1; ok&&i<n;j++,i++){ok=false;
   if(i==n-1)
   {
       if(arr[(i%n)]==0){
           ok=true;
       per1.push_back(i);
       per2.push_back((0));
       per3.push_back((i%n));}

   } else if(arr[(i+j%n)]==0) {
       arr[(i+j%n)]=1;
       per1.push_back(i);
       per2.push_back(j);
       per3.push_back(((j+i)%n));
       ok=true;

   }
    }
    if(!ok)
    {
        cout<<-1;
        return 0;
    }
    for (int i = 0; i < per1.size() ; ++i)
        cout<<per1[i]<<" ";
    cout<<'\n';
    for (int i = 0; i < per2.size() ; ++i)
        cout<<per2[i]<<" ";
    cout<<'\n';
    for (int i = 0; i < per3.size() ; ++i)
        cout<<per3[i]<<" ";
    cout<<'\n';
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;

	cin>>n;

	if(n%2==0) cout<<"-1"<<endl;
	else
	{
		for(int i=0;i<n;i++)
		   cout<<i<<" ";

		cout<<endl;

		for(int i=0;i<n;i++)
		   cout<<i<<" ";

		for(int i=0;i<n;i++)
		   cout<<(i+i)%n<<" ";

	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;

	cin>>n;

	if(n%2==0) cout<<"-1"<<endl;
	else
	{
		for(int i=0;i<n;i++)
		   cout<<i<<" ";

		cout<<endl;

		for(int i=0;i<n;i++)
		   cout<<i<<" ";

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;

	if(n%2==0){
		cout<<-1;
		return 0;
	}

	if(n==1){
		cout<<0<<endl;
		cout<<0<<endl;
		cout<<0<<endl;
		return 0;
	}

	int k = 0;
	int a1[n],a2[n];
	for(int i=0;i<n;i++){
		cout<<k<<" ";
		a1[i] = k;
		k++;
	}

	cout<<"\n";
	k=1;
	for(int i =0;i<n;i++){
		cout<<k<<" ";
		a2[i] = k;
		k = (k+1)%n;
	}
	cout<<"\n";

	for(int i =0;i<n;i++){
		cout<<(a2[i]+a1[i])%n<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;

	if(n%2==0){
		cout<<-1;
	}

	int k = 0;
	int a1[n],a2[n];
	for(int i=0;i<n;i++){
		cout<<k<<" ";
		a1[i] = k;
		k++;
	}

	cout<<"\n";
	k=1;
	for(int i =0;i<n;i++){
		cout<<k<<" ";
		a2[i] = k;
		k = (k+1)%n;
	}
	cout<<"\n";

	for(int i =0;i<n;i++){
		cout<<(a2[i]+a1[i])%n<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;

	if(n%2==0){
		cout<<-1;
		return 0;
	}

	int k = 0;
	int a1[n],a2[n];
	for(int i=0;i<n;i++){
		cout<<k<<" ";
		a1[i] = k;
		k++;
	}

	cout<<"\n";
	k=1;
	for(int i =0;i<n;i++){
		cout<<k<<" ";
		a2[i] = k;
		k = (k+1)%n;
	}
	cout<<"\n";

	for(int i =0;i<n;i++){
		cout<<(a2[i]+a1[i])%n<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;

	if(n%2==0){
		cout<<-1;
		return 0;
	}

	if(n==1){
		cout<<0<<endl;
		cout<<0<<endl;
		cout<<0<<endl;
	}

	int k = 0;
	int a1[n],a2[n];
	for(int i=0;i<n;i++){
		cout<<k<<" ";
		a1[i] = k;
		k++;
	}

	cout<<"\n";
	k=1;
	for(int i =0;i<n;i++){
		cout<<k<<" ";
		a2[i] = k;
		k = (k+1)%n;
	}
	cout<<"\n";

	for(int i =0;i<n;i++){
		cout<<(a2[i]+a1[i])%n<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll          long long
#define int 		long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
	//write here
	int n ;
    cin>>n;
    if(n%2==0){
        cout<<-1<<endl;
        return;
    }
    else{
        rep(i,0,n)cout<<i<<" ";
        cout<<endl;
        rep(i,0,n)cout<<i<<" ";
        cout<<endl;
        rep(i,0,n)cout<<(2*i)%n<<" ";
    }
}

int32_t main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code

		solve();
	return 0;
}


#include <bits/stdc++.h>
#define ll          long long
#define int 		long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
	//write here
	return;
}

int32_t main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	int n;
	cin>>n;
	if (n%2==0){
		cout<<-1<<endl;
		return 0;
	}
	else{
		rep(i,0,n)cout<<i<<" ";
		cout<<endl;
		rep(i,0,n)cout<<i<<" ";
		cout<<endl;
		rep(i,0,n)cout<<(2*i+n)%n<<" ";
		return 0;
	}
	int t;
	cin>>t;
	while(t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    if(n<=2) {cout<<"-1"<<"\n";exit(0);}
    for(int i=0;i<n;i++) cout<<i<<" ";cout<<"\n";
    for(int i=1;i<n;i++) cout<<i<<" ";cout<<"0\n";
    for(int i=1;i<n;i++) cout<<(2*i-1<n?2*i-1:2*i-1-n)<<" ";cout<<n-1<<"\n";
   return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long
#define pi pair<ll,ll>
#define vi vector<int>
#define sc second
#define ft first
#define p_q priority_queue
#define INF 10000000000
using namespace std;
const ll MOD=1e9+7;
const ll N=1e5+7;
ll n , m , ans=0 ;
vi a,b,c;
int main(){
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n ;
     if(n%2==0) return cout << -1 ,0;
     for(int i=0;i<n;i++) {
         a.pb(i);
         if(i+1!=n)b.pb(i+1);
         else b.pb(0);
     }
     for(int i=1;i<n;i+=2) c.pb(i);
     for(int i=0;i<n;i+=2) c.pb(i);
     for(int i=0;i<n;i++) cout<< a[i] << ' '; cout <<endl;
     for(int i=0;i<n;i++) cout<< b[i] << ' '; cout <<endl;
     for(int i=0;i<n;i++) cout<< c[i] << ' '; cout <<endl;
return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long
#define pi pair<ll,ll>
#define vi vector<int>
#define sc second
#define ft first
#define p_q priority_queue
#define INF 10000000000
using namespace std;
const ll MOD=1e9+7;
const ll N=1e5+7;
ll n , m , ans=0 ;
vi a,b,c;
int main(){
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n ;
     if(n%2==0) return cout << -1 ,0;
     for(int i=0;i<n;i++) a.pb(i),b.pb(n-i-1);
     for(int i=1;i<n;i+=2) c.pb(i);
     for(int i=0;i<n;i+=2) c.pb(i);
     for(int i=0;i<n;i++) cout<< a[i] << ' '; cout <<endl;
     for(int i=0;i<n;i++) cout<< b[i] << ' '; cout <<endl;
     for(int i=0;i<n;i++) cout<< c[i] << ' '; cout <<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
string get(int n){
  if(n==0)
    return "R";
  if(n==1)
    return "O";
  if(n==2)
    return "Y";
  if(n==3)
    return "G";
  if(n==4)
    return "B";
  if(n==5)
  return "I";
  if(n==6)
    return "V";
}
string get(char t){
  if(t=='2')
    return "2";
  if(t=='3')
    return "3";
  if(t=='4')
    return "322";
  if(t=='5')
    return "5";
  if(t=='6')
    return "53";
  if(t=='7')
    return "7";
  if(t=='8')
    return "7222";
  if(t=='9')
    return "7332";
}

void solve() {
  int i, j, n, m;

  cin>>n;
  if(n%2==0){
    cout<<-1;
    return ;
  }
  int a[n];
  int b[n];
  int c[n];
  for(int i =0; i<n; i++)
    a[i] = i;
  for(int i=0; i<(n-1); i++){
    b[i] = i+1;
  }
  b[n-1] = 0;

  for(int i=0; i<n; i++){
    c[i] = (a[i] + b[i])%n;
  }
  for(int i=0; i<n; i++)
    cout<<a[i]<<" ";
  cout<<"\n";
  for(int i=0; i<n; i++)
    cout<<b[i]<<" ";
  cout<<"\n";
  for(int i=0; i<n; i++)
    cout<<c[i]<<" ";
  cout<<"\n";

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
   // cin >> t;
    while(t--) {
      solve();
    }
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
    u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
string get(int n){
  if(n==0)
    return "R";
  if(n==1)
    return "O";
  if(n==2)
    return "Y";
  if(n==3)
    return "G";
  if(n==4)
    return "B";
  if(n==5)
  return "I";
  if(n==6)
    return "V";
}
string get(char t){
  if(t=='2')
    return "2";
  if(t=='3')
    return "3";
  if(t=='4')
    return "322";
  if(t=='5')
    return "5";
  if(t=='6')
    return "53";
  if(t=='7')
    return "7";
  if(t=='8')
    return "7222";
  if(t=='9')
    return "7332";
}

void solve() {
  int i, j, n, m;

  cin>>n;
  if(n<=2){
    cout<<-1;
    return ;
  }
  int a[n];
  int b[n];
  int c[n];
  for(int i =0; i<n; i++)
    a[i] = i;
  for(int i=0; i<(n-1); i++){
    b[i] = i+1;
  }
  b[n-1] = 0;

  for(int i=0; i<n; i++){
    c[i] = (a[i] + b[i])%n;
  }
  for(int i=0; i<n; i++)
    cout<<a[i]<<" ";
  cout<<"\n";
  for(int i=0; i<n; i++)
    cout<<b[i]<<" ";
  cout<<"\n";
  for(int i=0; i<n; i++)
    cout<<c[i]<<" ";
  cout<<"\n";

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
   // cin >> t;
    while(t--) {
      solve();
    }
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
    u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define MOD 1000000007
#define pb push_back
#define pll pair<ll,ll>

ll dx4[4] = {0, 1, 0, -1};
ll dy4[4] = {1, 0, -1, 0};
ll dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
ll dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

double calcDistance(double x1, double y1, double x2, double y2){ return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));}
ll power(ll b, ll p){
    if(p==0) return 1;
    ll t = power(b,p/2);
    t = t*t;
    if(p%2 == 1) t = t*b;
    return t;
}

// 0    1   2   3   4   5   6   7
// 0    1   2   3   5   6   7   4

// 0    2   4   6   8   10  12  14

// 0    2   4   6   0   2   4   6

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    int n;
    cin >> n;

    if(n==2){
        cout << -1;
        return 0;
    }

    for(int i=0; i<n; i++) cout << i << " ";
    cout << endl;

    if(n%2 == 1){
        for(int i=0; i<n; i++) cout << i << " ";
        int o = 0;
        cout << endl;
        for(int j=0; j<n; j++){
            if(o>=n) o=1;
            cout << o << " ";
            o+=2;
        }
    }
    else{
        for(int i=0; i<n; i++){
            if(i==n-1){
                cout << n/2+1 << endl;
                break;
            }
            if(i<=n/2) cout << i << " ";
            else cout << i+1 << " ";
        }
        int o = 0;
        for(int j=0; j<n; j++){
            if(o>=n) o=1;
            cout << o << " ";
            o+=2;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define MOD 1000000007
#define pb push_back
#define pll pair<ll,ll>

ll dx4[4] = {0, 1, 0, -1};
ll dy4[4] = {1, 0, -1, 0};
ll dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
ll dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

double calcDistance(double x1, double y1, double x2, double y2){ return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));}
ll power(ll b, ll p){
    if(p==0) return 1;
    ll t = power(b,p/2);
    t = t*t;
    if(p%2 == 1) t = t*b;
    return t;
}

// 0    1   2   3   4   5   6   7
// 0    1   2   3   5   6   7   4

// 0    2   4   6   8   10  12  14

// 0    2   4   6   0   2   4   6

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    int n;
    cin >> n;

    for(int i=0; i<n; i++) cout << i << " ";
    cout << endl;

    if(n%2 == 1){
        for(int i=0; i<n; i++) cout << i << " ";
        int o = 0;
        cout << endl;
        for(int j=0; j<n; j++){
            if(o>=n) o=1;
            cout << o << " ";
            o+=2;
        }
    }
    else{
        for(int i=0; i<n; i++){
            if(i==n-1){
                cout << n/2+1 << endl;
                break;
            }
            if(i<=n/2) cout << i << " ";
            else cout << i+1 << " ";
        }
        int o = 0;
        for(int j=0; j<n; j++){
            if(o>=n) o=1;
            cout << o << " ";
            o+=2;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define MOD 1000000007
#define pb push_back
#define pll pair<ll,ll>

ll dx4[4] = {0, 1, 0, -1};
ll dy4[4] = {1, 0, -1, 0};
ll dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
ll dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

double calcDistance(double x1, double y1, double x2, double y2){ return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));}
ll power(ll b, ll p){
    if(p==0) return 1;
    ll t = power(b,p/2);
    t = t*t;
    if(p%2 == 1) t = t*b;
    return t;
}

// 0    1   2   3   4   5   6   7
// 0    1   2   3   5   6   7   4

// 0    2   4   6   8   10  12  14

// 0    2   4   6   0   2   4   6

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    int n;
    cin >> n;

    if(n%2==0){
        cout << -1;
        return 0;
    }

    for(int i=0; i<n; i++) cout << i << " ";
    cout << endl;

    if(n%2 == 1){
        for(int i=0; i<n; i++) cout << i << " ";
        int o = 0;
        cout << endl;
        for(int j=0; j<n; j++){
            if(o>=n) o=1;
            cout << o << " ";
            o+=2;
        }
    }
    else{
        for(int i=0; i<n; i++){
            if(i==n-1){
                cout << n/2 << endl;
                break;
            }
            if(i<n/2) cout << i << " ";
            else cout << i+1 << " ";
        }
        int o = 0;
        for(int j=0; j<n; j++){
            if(o>=n) o=1;
            cout << o << " ";
            o+=2;
        }
    }

    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Karan Juneja
 */

#include <bits/stdc++.h>

using namespace std;
#define rep(i, c, n) for(i=c;i<n;i++)

long long power(long x, long n) {
    if (n == 0)
        return 1;
    if (n == 1)
        return x;
    long n2 = n / 2;
    long long po = power(x, n2);
    if (n % 2)
        return po * po * x;
    return po * po;
}

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

class CLuckyPermutationTriple {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n, i;
        cin >> n;
        if (n < 3) {
            cout << "-1\n";
            return;
        }
        vector<int> V[3];
        rep(i, 0, 3) V[i].resize(n);
        rep(i, 0, n) {
            V[0][i] = i;
            V[1][i] = (i + 1) % n;
            V[2][i] = (V[0][i] + V[1][i]) % n;
        }
        rep(i, 0, 3) {
            for (auto it:V[i]) {
                cout << it << " ";
            }
            cout << "\n";
        }
    }
};

int main() {
    CLuckyPermutationTriple solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Karan Juneja
 */

#include <bits/stdc++.h>

using namespace std;
#define rep(i, c, n) for(i=c;i<n;i++)
#define S second

long long power(long x, long n) {
    if (n == 0)
        return 1;
    if (n == 1)
        return x;
    long n2 = n / 2;
    long long po = power(x, n2);
    if (n % 2)
        return po * po * x;
    return po * po;
}

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

class CLuckyPermutationTriple {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n, i;
        cin >> n;
        vector<int> V[3];
        rep(i, 0, 3) V[i].resize(n);
        set<int> S;
        rep(i, 0, n) {
            V[0][i] = i;
            V[1][i] = (i + 1) % n;
            V[2][i] = (V[0][i] + V[1][i]) % n;
            S.insert(V[2][i]);
        }
        if (S.size() != n) {
            cout << "-1\n";
            return;
        }
        rep(i, 0, 3) {
            for (auto it:V[i]) {
                cout << it << " ";
            }
            cout << "\n";
        }
    }
};

int main() {
    CLuckyPermutationTriple solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Karan Juneja
 */

#include <bits/stdc++.h>

using namespace std;
#define rep(i, c, n) for(i=c;i<n;i++)
#define S second

long long power(long x, long n) {
    if (n == 0)
        return 1;
    if (n == 1)
        return x;
    long n2 = n / 2;
    long long po = power(x, n2);
    if (n % 2)
        return po * po * x;
    return po * po;
}

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

class CLuckyPermutationTriple {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n, i;
        cin >> n;
        if (n < 3) {
            cout << "-1\n";
            return;
        }
        vector<int> V[3];
        rep(i, 0, 3) V[i].resize(n);
        set<int> S;
        rep(i, 0, n) {
            V[0][i] = i;
            V[1][i] = (i + 1) % n;
            V[2][i] = (V[0][i] + V[1][i]) % n;
            S.insert(V[2][i]);
        }
        if (S.size() != n) {
            cout << "-1\n";
            return;
        }
        rep(i, 0, 3) {
            for (auto it:V[i]) {
                cout << it << " ";
            }
            cout << "\n";
        }
    }
};

int main() {
    CLuckyPermutationTriple solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


#include "bits/stdc++.h"
using namespace std;

void p(vector< int> a) {
    int x = 0;
    for (int y : a) {
        if (x) printf(" ");
        printf("%d", y);
        x = 1;
    }
    puts("");
}

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) return !printf("-1\n");
    vector< int> a, b, c;
    for (int i = 0; i < n; ++i) a.emplace_back(i), b.emplace_back(i);
    for (int i = 0; i < n; ++i) c.emplace_back((a[i] + b[i]) % n);
    p(a); p(b); p(c);
}


#include "bits/stdc++.h"
using namespace std;

void p(vector< int> a) {
    int x = 0;
    for (int y : a) {
        if (x) printf(" ");
        printf("%d", y);
        x = 1;
    }
    puts("");
}

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) return !printf("-1\n");
    vector< int> a, c;
    for (int i = 0; i < n; ++i) a.emplace_back(i), c.emplace_back((i + i) % n);
    p(a); p(a); p(c);
}


/*
   وَعَلَى اللَّهِ فَلْيَتَوَكَّلِ الْمُؤْمِنُونَ
*/

#include <bits/stdc++.h>
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

int mod = 1e9 + 7 ;

ll binpow(ll a, ll b){
   ll res = 1 ;
   while(b > 0){
       if(b & 1) res = (res % mod) * (a % mod), res %= mod ;
       a = (a % mod) * (a % mod) ;
       a %= mod ;
       b >>= 1 ;
   }
   return res ;
}

ll divide(ll a, int b){
    return ((a % mod) * binpow(b, mod - 2) % mod) % mod;
}

ll nCr(ll n, ll k)
{
    ll res = 1;

    // Since C(n, k) = C(n, n-k)
    if (k > n - k)
        k = n - k;

    // Calculate value of
    // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
    for (int i = 0; i < k; ++i)
    {
        res = ((res % mod) * ((n - i) % mod)) % mod;
        res = divide(res, i + 1);
    }

    return res;
}

int main()
{

//   freopen("in.txt", "r", stdin) ;
   ios :: sync_with_stdio(0) ;
   cin.tie(0) ;
   cout.tie(0) ;

   int n;
   cin >> n ;

   if(n % 2 == 0) return cout << "-1\n", 0;

   for(int i = 0 ; i < n ; i++){
     cout << i << " ";
   }

   cout << "\n" ;
   for(int i = 0 ; i < n ; i++){
     cout << i << " ";
   }

   cout << "\n" ;
   for(int i = 0 ; i < n ; i++){
     cout << i << " ";
   }

}


/*
   وَعَلَى اللَّهِ فَلْيَتَوَكَّلِ الْمُؤْمِنُونَ
*/

#include <bits/stdc++.h>
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

int mod = 1e9 + 7 ;

ll binpow(ll a, ll b){
   ll res = 1 ;
   while(b > 0){
       if(b & 1) res = (res % mod) * (a % mod), res %= mod ;
       a = (a % mod) * (a % mod) ;
       a %= mod ;
       b >>= 1 ;
   }
   return res ;
}

ll divide(ll a, int b){
    return ((a % mod) * binpow(b, mod - 2) % mod) % mod;
}

ll nCr(ll n, ll k)
{
    ll res = 1;

    // Since C(n, k) = C(n, n-k)
    if (k > n - k)
        k = n - k;

    // Calculate value of
    // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
    for (int i = 0; i < k; ++i)
    {
        res = ((res % mod) * ((n - i) % mod)) % mod;
        res = divide(res, i + 1);
    }

    return res;
}

int main()
{

//   freopen("in.txt", "r", stdin) ;
   ios :: sync_with_stdio(0) ;
   cin.tie(0) ;
   cout.tie(0) ;

   int n;
   cin >> n ;

   if(n % 2 == 0) return cout << "-1\n", 0;

   for(int i = 0 ; i < n ; i++){
     cout << i << " ";
   }

   cout << "\n" ;
   for(int i = 0 ; i < n ; i++){
     cout << i << " ";
   }

   cout << "\n" ;
   for(int i = 0 ; i < n ; i++){
     cout << (i + i) % n << " ";
   }

}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007

void inp()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
ll min(ll a,ll b)
{
    if(a<b)
        return a;
    else
        return b;
}

ll max(ll a,ll b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main() {
   fio;

   int n;
   cin>>n;

   // if(n<=2)
   // {
   // 	cout<<"-1"<<endl;
   // 	return 0;
   // }
   unordered_map<int,int> mp;
   vector<int> a(n);
   vector<int> b(n);
   vector<int> c(n);
   for(int i=0;i<n;i++)
   {
   		a[i]=i;
   		b[i]=(i+1)%n;
   		c[i]=(a[i]+b[i])%n;
   		if(mp.find(c[i])!=mp.end())
   		{
   			cout<<"-1"<<endl;
   			return 0;
   		}
   		mp[c[i]]=1;
   }
   for(int i=0;i<n;i++)
   	cout<<a[i]<<" ";
   cout<<endl;

   for(int i=0;i<n;i++)
   	cout<<b[i]<<" ";
   cout<<endl;

   for(int i=0;i<n;i++)
   	cout<<c[i]<<" ";
   cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007

void inp()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
ll min(ll a,ll b)
{
    if(a<b)
        return a;
    else
        return b;
}

ll max(ll a,ll b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main() {
   fio;

   int n;
   cin>>n;

   if(n<=2)
   {
   	cout<<"-1"<<endl;
   	return 0;
   }
   unordered_map<int,int> mp;
   vector<int> a(n);
   vector<int> b(n);
   vector<int> c(n);
   for(int i=0;i<n;i++)
   {
   		a[i]=b[i]=i;
   		c[i]=(a[i]+b[i])%n;
   		if(mp.find(c[i])!=mp.end())
   		{
   			cout<<"-1"<<endl;
   			return 0;
   		}
   		mp[c[i]]=1;
   }
   for(int i=0;i<n;i++)
   	cout<<a[i]<<" ";
   cout<<endl;

   for(int i=0;i<n;i++)
   	cout<<b[i]<<" ";
   cout<<endl;

   for(int i=0;i<n;i++)
   	cout<<c[i]<<" ";
   cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007

void inp()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
ll min(ll a,ll b)
{
    if(a<b)
        return a;
    else
        return b;
}

ll max(ll a,ll b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main() {
   fio;

   int n;
   cin>>n;

   if(n<=2)
   {
   	cout<<"-1"<<endl;
   	return 0;
   }
   unordered_map<int,int> mp;
   vector<int> a(n);
   vector<int> b(n);
   vector<int> c(n);
   for(int i=0;i<n;i++)
   {
   		a[i]=i;
   		b[i]=(i+1)%n;
   		c[i]=(a[i]+b[i])%n;
   		if(mp.find(c[i])!=mp.end())
   		{
   			cout<<"-1"<<endl;
   			return 0;
   		}
   		mp[c[i]]=1;
   }
   for(int i=0;i<n;i++)
   	cout<<a[i]<<" ";
   cout<<endl;

   for(int i=0;i<n;i++)
   	cout<<b[i]<<" ";
   cout<<endl;

   for(int i=0;i<n;i++)
   	cout<<c[i]<<" ";
   cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007

void inp()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
ll min(ll a,ll b)
{
    if(a<b)
        return a;
    else
        return b;
}

ll max(ll a,ll b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main() {
   fio;

   int n;
   cin>>n;

   if(n<=2)
   {
   	cout<<"-1"<<endl;
   	return 0;
   }

   vector<int> a(n);
   vector<int> b(n);
   vector<int> c(n);
   for(int i=0;i<n;i++)
   {
   		a[i]=b[i]=i;
   		c[i]=(a[i]+b[i])%n;
   }
   for(int i=0;i<n;i++)
   	cout<<a[i]<<" ";
   cout<<endl;

   for(int i=0;i<n;i++)
   	cout<<b[i]<<" ";
   cout<<endl;

   for(int i=0;i<n;i++)
   	cout<<c[i]<<" ";
   cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pi pair < int, int >
#define pl pair < long long, long long >
typedef bitset< 16 > MASK;

int n;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	freopen("output.txt", "w", stdout);

	cin >> n;

	if(n <= 2)
		return cout << -1, 0;

	for(int i = 0; i < n; i ++)
		cout << i << " ";

	cout << "\n";

	for(int i = 1; i <= n; i ++)
		cout << i % n << " ";

	cout << "\n";

	for(int i = 1; i < n; i += 2)
		cout << i << " ";

	for(int i = 0; i < n; i += 2)
		cout << i << " ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pi pair < int, int >
#define pl pair < long long, long long >
typedef bitset< 16 > MASK;

int n;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	freopen("output.txt", "w", stdout);

	cin >> n;

	if(n % 2 == 0 || n < 2)
		return cout << -1, 0;

	for(int i = 0; i < n; i ++)
		cout << i << " ";

	cout << "\n";

	for(int i = 1; i <= n; i ++)
		cout << i % n << " ";

	cout << "\n";

	for(int i = 1; i < n; i += 2)
		cout << i << " ";

	for(int i = 0; i < n; i += 2)
		cout << i << " ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pi pair < int, int >
#define pl pair < long long, long long >
typedef bitset< 16 > MASK;

int n;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	freopen("output.txt", "w", stdout);

	cin >> n;

	if(n % 2 == 0)
		return cout << -1, 0;

	for(int i = 0; i < n; i ++)
		cout << i << " ";

	cout << "\n";

	for(int i = 1; i <= n; i ++)
		cout << i % n << " ";

	cout << "\n";

	for(int i = 1; i < n; i += 2)
		cout << i << " ";

	for(int i = 0; i < n; i += 2)
		cout << i << " ";
	return 0;
}


    #include<bits/stdc++.h>

    #define hell                         1000000007
    #define lcm(a,b)                     (a*b)/__gcd(a,b)
    #define ll                           long long
    #define vll                          vector<ll>
    #define vi                           vector<long long>
    #define pll                          vector< pair<ll,ll> >
    #define pb                           push_back
    //#define mp                           make_pair
    #define all(v)                       v.begin(),v.end()
    #define lbnd                         lower_bound
    #define ubnd                         upper_bound
    #define bs                           binary_search
    #define F                            first
    #define S                            second
    #define rep(i,a,b)                   for(i=a;i<b;i++)
    #define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
    #define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
    #define ret(x)                       return cout<<x,0;
    #define dbg(x)                       cout << #x << " is " << x << endl;
    //#define endl                           '\n'

    // Debug //

    #define trace(x)                 cerr << #x << ": " << x << endl;
    #define trace1(x)                cerr << #x << ": " << x << endl;
    #define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
    #define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
    #define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
    #define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
    #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

    using namespace std;
    #define MAXN   1000005

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);

        ll n;
        cin>>n;
        ll arr[n];
        ll i,j;
        for(i=0;i<n;i++)
        {
        	arr[i]=i;
        }
        if(n%2==0)
        {
        	cout<<-1<<endl;
        }
        else
        {

        	for(i=0;i<n;i++)
        	{
        		cout<<arr[i]<<" ";
        	}
        	cout<<endl;
        	for(i=0;i<n;i++)
        	{
        		cout<<arr[i]<<" ";
        	}
        	cout<<endl;

        	for(i=0;i<n;i++)
        	{
        		cout<<(arr[i]+arr[i])%n<<" ";
        	}

        }

    return 0;
    }


    #include<bits/stdc++.h>

    #define hell                         1000000007
    #define lcm(a,b)                     (a*b)/__gcd(a,b)
    #define ll                           long long
    #define vll                          vector<ll>
    #define vi                           vector<long long>
    #define pll                          vector< pair<ll,ll> >
    #define pb                           push_back
    //#define mp                           make_pair
    #define all(v)                       v.begin(),v.end()
    #define lbnd                         lower_bound
    #define ubnd                         upper_bound
    #define bs                           binary_search
    #define F                            first
    #define S                            second
    #define rep(i,a,b)                   for(i=a;i<b;i++)
    #define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
    #define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
    #define ret(x)                       return cout<<x,0;
    #define dbg(x)                       cout << #x << " is " << x << endl;
    //#define endl                           '\n'

    // Debug //

    #define trace(x)                 cerr << #x << ": " << x << endl;
    #define trace1(x)                cerr << #x << ": " << x << endl;
    #define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
    #define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
    #define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
    #define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
    #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

    using namespace std;
    #define MAXN   1000005

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);

        ll n;
        cin>>n;
        ll arr[n];
        ll i,j;
        for(i=0;i<n;i++)
        {
        	arr[i]=i;
        }
        if(n%2==0)
        {
        	cout<<-1<<endl;
        }
        else
        {

        	for(i=0;i<n;i++)
        	{
        		cout<<arr[i]<<" ";
        	}
        	cout<<endl;
        	for(i=n-1;i>=0;i--)
        	{
        		cout<<arr[i]<<" ";
        	}
        	cout<<endl;

        	for(i=0;i<n;i++)
        	{
        		cout<<(arr[i]+arr[i])%n<<" ";
        	}

        }

    return 0;
    }


    #include<bits/stdc++.h>

    #define hell                         1000000007
    #define lcm(a,b)                     (a*b)/__gcd(a,b)
    #define ll                           long long
    #define vll                          vector<ll>
    #define vi                           vector<long long>
    #define pll                          vector< pair<ll,ll> >
    #define pb                           push_back
    //#define mp                           make_pair
    #define all(v)                       v.begin(),v.end()
    #define lbnd                         lower_bound
    #define ubnd                         upper_bound
    #define bs                           binary_search
    #define F                            first
    #define S                            second
    #define rep(i,a,b)                   for(i=a;i<b;i++)
    #define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
    #define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
    #define ret(x)                       return cout<<x,0;
    #define dbg(x)                       cout << #x << " is " << x << endl;
    //#define endl                           '\n'

    // Debug //

    #define trace(x)                 cerr << #x << ": " << x << endl;
    #define trace1(x)                cerr << #x << ": " << x << endl;
    #define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
    #define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
    #define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
    #define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
    #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

    using namespace std;
    #define MAXN   1000005

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);

        ll n;
        cin>>n;
        ll arr[n];
        ll i,j;
        for(i=0;i<n;i++)
        {
        	arr[i]=i;
        }
        if(n%2==0)
        {
        	cout<<-1<<endl;
        }
        else
        {

        	for(i=0;i<n;i++)
        	{
        		cout<<arr[i]<<" ";
        	}
        	cout<<endl;
        	for(i=n-1;i>=0;i--)
        	{
        		cout<<arr[i]<<" ";
        	}
        	cout<<endl;

        	for(i=0;i<n;i++)
        	{
        		cout<<(arr[i]+arr[n-i-1])%n<<" ";
        	}

        }

    return 0;
    }


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
//#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*********************************************START**************************************************************************/
//int dp[10001];

//int dest;

//int cal_cost(int height[], int curr ){
	//if(curr == dest){
		//return 0;
	//}
	//if(dp[curr] != -1){
		//return dp[curr];
	//}
	//else{
		//if(curr + 1 == dest){
			//return dp[curr+1] =  abs(height[curr] - height[curr+1]);
		//}else{
			//return dp[curr] = min(abs(height[curr] -

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T  = 1;
	//int T;
	//cin >> T;
	// cin.ignore(); //must be there when using getline(cin, s)
	while (T--)
	{
		int n; cin >> n;
		if(n&1){
			vi p1, p2, p3;
			for(int i=0; i<n; i++){
				int a;
				if(i == n-1){
					a = 0;
				}else{
					a = i+1;
				}
				p1.eb(i); p2.eb(a); p3.eb((i+a)%n);
			}
			for(auto i : p1){
				cout << i << " ";
			}cout << endl;
			for(auto i : p2){
				cout << i << " ";
			}cout << endl;
			for(auto i : p3){
				cout << i  << " ";
			}cout << endl;
		}else{
			cout << -1 << endl;
		}

	}

	return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
//#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*********************************************START**************************************************************************/
//int dp[10001];

//int dest;

//int cal_cost(int height[], int curr ){
	//if(curr == dest){
		//return 0;
	//}
	//if(dp[curr] != -1){
		//return dp[curr];
	//}
	//else{
		//if(curr + 1 == dest){
			//return dp[curr+1] =  abs(height[curr] - height[curr+1]);
		//}else{
			//return dp[curr] = min(abs(height[curr] -

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T  = 1;
	//int T;
	//cin >> T;
	// cin.ignore(); //must be there when using getline(cin, s)
	while (T--)
	{
		int n; cin >> n;
		if(n&1){
			vi p1, p2, p3;
			for(int i=0; i<n; i++){
				int a;
				if(i == n){
					a = 0;
				}else{
					a = i+1;
				}
				p1.eb(i); p2.eb(a); p3.eb((i+a)%n);
			}
			for(auto i : p1){
				cout << i << " ";
			}cout << endl;
			for(auto i : p2){
				cout << i << " ";
			}cout << endl;
			for(auto i : p3){
				cout << i  << " ";
			}cout << endl;
		}else{
			cout << -1 << endl;
		}

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

ll ans[sz];
vector<int> ar[sz];

void dfs(int u,int pr){
    ans[u]=0;
    for(int v:ar[u]){
        if(pr!=v){
            dfs(v,u);
            ans[u]=max(ans[u],ans[v]+1);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n&1==0){
            cout<<-1<<endl;
        }
        else{
            for(int i=0;i<n;i++){
                cout<<i<<" ";
            }
            for(int j=0;j<n;j++){
                cout<<j<<" ";
            }
            for(int i=0;i<n;i++){
                cout<<((2*i)%n)<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

ll ans[sz];
vector<int> ar[sz];

void dfs(int u,int pr){
    ans[u]=0;
    for(int v:ar[u]){
        if(pr!=v){
            dfs(v,u);
            ans[u]=max(ans[u],ans[v]+1);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if((n&1)==0){
            cout<<-1<<endl;
        }
        else{
            for(int i=0;i<n;i++){
                cout<<i<<" ";
            }
            for(int j=0;j<n;j++){
                cout<<j<<" ";
            }
            for(int i=0;i<n;i++){
                cout<<((2*i)%n)<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

ll ans[sz];
vector<int> ar[sz];

void dfs(int u,int pr){
    ans[u]=0;
    for(int v:ar[u]){
        if(pr!=v){
            dfs(v,u);
            ans[u]=max(ans[u],ans[v]+1);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n&1){
            cout<<-1<<endl;
        }
        else{
            for(int i=0;i<n;i++){
                cout<<i<<" ";
            }
            for(int j=0;j<n;j++){
                cout<<j<<" ";
            }
            for(int i=0;i<n;i++){
                cout<<((2*i)%n)<<endl;
            }
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int len = 1e5 + 5;
int a[len], b[len];
int main()
{
    int n;
    scanf("%d", &n);
    if(n % 2 == 0){
        printf("-1");
        return 0;
    }
    for(int i = 0; i < n; i++){
        printf("%d ", i);
        a[i] = i;
    }
    printf("\n");
    for(int i = 1; i < n; i++){
        printf("%d ", i);
        b[i] = i;
    }
    printf("%d\n", 0);
    a[0] = 0;
    for(int i = 0; i < n; i++){
        int x = (a[i] + b[i]) % n;
        printf("%d ", x);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int len = 1e5 + 5;
int a[len], b[len];
int main()
{
    int n;
    scanf("%d", &n);
    if(n % 2 == 0){
        printf("-1");
        return 0;
    }
    for(int i = 0; i < n; i++){
        printf("%d ", i);
        a[i] = i;
    }
    printf("\n");
    for(int i = 1; i < n; i++){
        printf("%d ", i);
        b[i - 1] = i;
    }
    printf("%d\n", 0);
    b[n - 1] = 0;
    for(int i = 0; i < n; i++){
        int x = (a[i] + b[i]) % n;
        printf("%d ", x);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int len = 1e5 + 5;
int a[len], b[len];
int main()
{
    int n;
    scanf("%d", &n);
    if(n % 2 == 0){
        printf("-1");
        return 0;
    }
    for(int i = 0; i < n; i++){
        printf("%d ", i);
        a[i] = i;
    }
    printf("\n");
    for(int i = 1; i < n; i++){
        printf("%d ", i);
        a[i] = i;
    }
    printf("%d\n", 0);
    a[0] = 0;
    for(int i = 0; i < n; i++){
        int x = (a[i] + b[i]) % n;
        printf("%d ", x);
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
	ll n;
	cin >> n;

	if(n == 1) {cout<<0<<endl<<0<<endl<<0<<endl; return 0;}
	if(n%2 == 0) {cout<<-1<<endl; return 0;}

	ll a[n], b[n], c[n];

	for(ll i = 0; i < n; i++){
		c[i] = i;
		b[i] = n - 1 - i;
	}
	for(ll i = 0;i < n;i++) a[i] = (c[i] - b[i])%n + ((c[i] >= b[i])? 0:n);
	for(ll i = 0;i < n;i++) cout<<a[i]<<" ";
	cout<<endl;
	for(ll i = 0;i < n;i++) cout<<b[i]<<" ";
	cout<<endl;
	for(ll i = 0;i < n;i++) cout<<c[i]<<" ";
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
	ll n;
	cin >> n;

	if(n%2 == 0 || n <= 2) {cout<<-1<<endl; return 0;}

	ll a[n], b[n], c[n];

	for(ll i = 0; i < n; i++){
		c[i] = i;
		b[i] = n - 1 - i;
	}
	for(ll i = 0;i < n;i++) a[i] = (c[i] - b[i])%n + ((c[i] >= b[i])? 0:n);
	for(ll i = 0;i < n;i++) cout<<a[i]<<" ";
	cout<<endl;
	for(ll i = 0;i < n;i++) cout<<b[i]<<" ";
	cout<<endl;
	for(ll i = 0;i < n;i++) cout<<c[i]<<" ";
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

chal toh 1 ke liye allowed?
int main(){
	ll n;
	cin >> n;

	if(n == 1) {cout<<0<<endl<<0<<endl<<0<<endl; return 0;}
	if(n%2 == 0) {cout<<-1<<endl; return 0;}

	ll a[n], b[n], c[n];

	for(ll i = 0; i < n; i++){
		c[i] = i;
		b[i] = n - 1 - i;
	}
	for(ll i = 0;i < n;i++) a[i] = (c[i] - b[i])%n + ((c[i] >= b[i])? 0:n);
	for(ll i = 0;i < n;i++) cout<<a[i]<<" ";
	cout<<endl;
	for(ll i = 0;i < n;i++) cout<<b[i]<<" ";
	cout<<endl;
	for(ll i = 0;i < n;i++) cout<<c[i]<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           (long long)1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigint        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
#define SHUF(v) shuffle(aint(v), RNG);
// Use mt19937_64 for 64 bit random numbers.

template <typename T>
T ceil(T a, T b){ return (a+b-1)/b; }

template<typename T>
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
void solve(){
    int n; cin>>n;
    if(n&1) {
        vector<int> a, b, c;
        FOR(i, 0, n) {
            a.pb(i);
        }
        FOR(i, 1, n) {
            b.pb(i);
        }
        b.pb(0);
        FOR(i, 0, n) {
            c.pb((a[i]+b[i])%n);
        }
        for(int x:a)
            cout<<x<<' ';
        cout<<endl;
        for(int x:b)
            cout<<x<<' ';
        cout<<endl;
        for(int x:c)
            cout<<x<<' ';
        cout<<endl;

    } else {
        cout<<-1;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    FOR(i, 1, t+1){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           (long long)1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigint        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
#define SHUF(v) shuffle(aint(v), RNG);
// Use mt19937_64 for 64 bit random numbers.

template <typename T>
T ceil(T a, T b){ return (a+b-1)/b; }

template<typename T>
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
void solve(){
    int n; cin>>n;
    if(n&1) {
        FOR(i, 0, n) {
            cout<<i<<' ';
        }
        cout<<endl;
        FOR(i, 1, n) {
            cout<<i<<' ';
        }
        cout<<0;
    } else {
        cout<<-1;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    FOR(i, 1, t+1){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;

}


#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    if(!(n&1)) {
        cout << -1 << endl;
        return 0;
    }
    int a[n], b[n], c[n];
    for(int i = 0; i < n-1; i++) {
        a[i] = i;
        b[i] = i+1;
        c[i] = (a[i] + b[i]) % n;
    }
    a[n-1] = n-1;
    b[n-1] = 0;
    c[n-1] = 0;
    for(int i = 0; i < n; i++) cout << a[i] << ' ';
    cout << endl;
    for(int i = 0; i < n; i++) cout << b[i] << ' ';
    cout << endl;
    for(int i = 0; i < n; i++) cout << c[i] << ' ';
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    if(!(n&1)) {
        cout << -1 << endl;
        return 0;
    }
    int a[n], b[n], c[n];
    for(int i = 0; i < n-1; i++) {
        a[i] = i;
        b[i] = i+1;
        c[i] = (a[i] + b[i]) % n;
    }
    a[n-1] = n-1;
    b[n-1] = 0;
    c[n-1] = 0;
    for(int i = 0; i < n; i++) cout << a[i];
    cout << endl;
    for(int i = 0; i < n; i++) cout << b[i];
    cout << endl;
    for(int i = 0; i < n; i++) cout << c[i];
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    if(!(n&1)) {
        cout << -1 << endl;
        return 0;
    }
    int a[n], b[n], c[n];
    for(int i = 0; i < n-1; i++) {
        a[i] = i;
        b[i] = i+1;
        c[i] = (a[i] + b[i]) % n;
    }
    a[n-1] = n-1;
    b[n-1] = 0;
    c[n-1] = n-1;
    for(int i = 0; i < n; i++) cout << a[i] << ' ';
    cout << endl;
    for(int i = 0; i < n; i++) cout << b[i] << ' ';
    cout << endl;
    for(int i = 0; i < n; i++) cout << c[i] << ' ';
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
    cin>>n;
    if(n%2==0) cout<<-1;
    else
    {
        vector<int> v1(n), v2(n);
        v1[0]=n-1;v2[0]=n-1;
        for(int i=1; i<n; i++) {v1[i]=i-1; v2[i]=(i+v1[i])%n;}
        for(int i=0; i<n; i++) cout<<i<<" ";
        cout<<endl;
        for(int i=0; i<n; i++) cout<<v1[i]<<" ";
        cout<<endl;
        for(int i=0; i<n; i++) cout<<v2[i]<<" ";
        cout<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
    cin>>n;
    if(n<=2) cout<<-1;
    else
    {
        vector<int> v1(n), v2(n);
        v1[0]=n-1;v2[0]=n-1;
        for(int i=1; i<n; i++) {v1[i]=i-1; v2[i]=(i+v1[i])%n;}
        for(int i=0; i<n; i++) cout<<i<<" ";
        cout<<endl;
        for(int i=0; i<n; i++) cout<<v1[i]<<" ";
        cout<<endl;
        for(int i=0; i<n; i++) cout<<v2[i]<<" ";
        cout<<endl;
    }
	return 0;
}


#include<stdio.h>
#include<string.h>
typedef __int64 lld;
const int MAXN=1000005;
const int MOD=1000000007;
char str[MAXN];
lld l[MAXN];
lld r[MAXN];
int suml[MAXN];
int sumr[MAXN];
int main()
{
	int n,k,i,j;
	scanf("%d%d%s",&n,&k,str+1);
	l[0]=1;
	for(i=1;i<=n;i++)
	{
		l[i]=l[i-1];
		if(str[i]=='X')
			l[i]+=l[i-1];
		if(str[i]!='W')
			suml[i]=suml[i-1]+1;
		if(suml[i]>=k&&str[i-k]!='B')
		{
			if(i-k==0)
				l[i]--;
			else
				l[i]-=l[i-k-1];
		}
		l[i]%=MOD;
	}
	r[n+1]=1;r[n+2]=1;
	for(i=n;i>=1;i--)
	{
		r[i]=r[i+1];
		if(str[i]=='X')
			r[i]+=r[i+1];
		if(str[i]!='B')
			sumr[i]=sumr[i+1]+1;
		if(sumr[i]>=k&&str[i+k]!='W')
			r[i]-=r[i+k+1];
		r[i]%=MOD;
	}
	lld ans=0,sum=0;
	for(i=n;i>=1;i--)
	{
		if(str[i+1]=='X')
			sum<<=1;
		if(sumr[i+1]>=k&&str[i+k+1]!='W')
			sum+=r[i+k+2];
		sum%=MOD;
		if(suml[i]>=k&&str[i-k]!='B')
		{
			if(i-k==0)
				ans+=sum;
			else
				ans+=l[i-k-1]*sum;
		}
		ans%=MOD;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<stdio.h>
#include<string.h>
typedef __int64 lld;
const int MAXN=1000005;
const int MOD=1000000007;
char str[MAXN];
lld l[MAXN];
lld r[MAXN];
int suml[MAXN];
int sumr[MAXN];
int main()
{
    int n,k,i,j;
    scanf("%d%d%s",&n,&k,str+1);
    l[0]=1;
    for(i=1;i<=n;i++)
    {
        l[i]=l[i-1];
        if(str[i]=='X')
            l[i]+=l[i-1];
        if(str[i]!='W')
            suml[i]=suml[i-1]+1;
        if(suml[i]>=k&&str[i-k]!='B')
        {
            if(i-k==0)
                l[i]--;
            else
                l[i]-=l[i-k-1];
        }
        l[i]=(l[i]%MOD+MOD)%MOD;
    }
    r[n+1]=1;r[n+2]=1;
    for(i=n;i>=1;i--)
    {
        r[i]=r[i+1];
        if(str[i]=='X')
            r[i]+=r[i+1];
        if(str[i]!='B')
            sumr[i]=sumr[i+1]+1;
        if(sumr[i]>=k&&str[i+k]!='W')
            r[i]-=r[i+k+1];
        r[i]=(r[i]%MOD+MOD)%MOD;
    }
    lld ans=0,sum=0;
    for(i=n;i>=1;i--)
    {
        if(str[i+1]=='X')
            sum<<=1;
        if(sumr[i+1]>=k&&str[i+k+1]!='W')
            sum+=r[i+k+2];
        sum%=MOD;
        if(suml[i]>=k&&str[i-k]!='B')
        {
            if(i-k==0)
                ans+=sum;
            else
                ans+=l[i-k-1]*sum;
        }
        ans%=MOD;
    }
    printf("%I64d\n",ans);
    return 0;
}


#pragma comment(linker, "/STACK:65777216")

#include <algorithm>
#include <iostream>
#include <string>
#include<sstream>
#include<string.h>
#include <cstdio>
#include <cassert>
#include <complex>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include<stack>
#include <set>
#include <map>
#include<ctime>
#include<list>

using namespace std;

typedef long long ll;
typedef unsigned long ull;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;

#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define SORT(v) sort((v).begin(),(v).end())
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back

const int mod = 1000000007;

int n,k;
char s[1111111];
char t[1111111];
vi v1,v2;

int sum[1111111];
vi tmp;

int tp[1111111];
int w[1111111];
int q[1111111];
int sw[1111111];

vi solve(char *s){
	tmp.clear();
	tmp.resize(n, 0);
	CL(w,0);CL(sw,0);CL(q,0);
	int num = 0;
	int lastw = -1;
	REP(i,n){
		if(s[i]=='X') q[i]=1;
		if(i) q[i]+=q[i-1];
		if(s[i]=='B' || s[i]=='X') num++;
		else num = 0;

		if(num>=k){
			int pos = i - k;
			if(pos<0) tmp[i] = 1;
			else  tmp[i] = w[pos];
		}

		w[i] = 0;
		if(s[i]=='W' || s[i]=='X'){
			if(i==0) w[i] = 1;
			else {
				if(i-1-k<-1){
					w[i] = tp[q[i-1]];
				}else{
					int pos = i-1-k;
					if(lastw>pos) pos = lastw-1;
					w[i] += sw[i-1] - (pos>=0?sw[pos]:0);
				}
				w[i]%=mod;
				if(w[i]<0) w[i]+=mod;
			}
		}

		sw[i] = w[i];
		if(i) sw[i]+=sw[i-1],sw[i]%=mod;

	//	cout<<i<<" -> w[i] "<<w[i]<<"   sw[i] "<<sw[i]<<"  tmp "<<tmp[i]<<endl;
		if(s[i]=='W') lastw=i;
	}

	return tmp;
}

int go(string z, int pos){
	if(pos==z.size()){
		int num=0;
		REP(i,n){
			if(z[i]=='B') num++;
			else num = 0;
			if(num==k){
				num=0;
				FOR(j,i,n){
					if(z[j]=='W') num++;
					else num=0;
					if(num==k) return 1;
				}
				break;
			}
		}
		return 0;
	}
	int res = 0;
	if(z[pos]=='X'){
		string t1 = z;
		t1[pos]='B';
		res += go(t1, pos+1);
		t1[pos]='W';
		res += go(t1, pos+1);
		return res;
	}
	return go(z,pos+1);
}
int num(){
	string z = s;
	return go(z, 0);
}

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

	tp[0]= 1;
	FOR(i,1,1111111) tp[i]=(tp[i-1]*2)%mod;
	cin>>n>>k;

	scanf(" %s",s);

	v1 = solve(s);
	//REP(i,v1.size()) cout<<v1[i]<<' ';puts("");

	REP(i,n) t[i] = s[n-1-i];
	REP(i,n) if(t[i]=='W') t[i]='B';
	else if(t[i]=='B') t[i]='W';
	v2 = solve(t);
	reverse(v2.begin(),v2.end());
	//REP(i,v2.size()) cout<<v2[i]<<' ';puts("");

	ll res = 0;
	REP(i,v1.size()){
		sum[i] = v1[i];
		if(i){
			int add = sum[i-1];
			if(s[i]=='X') add*=2,add%=mod;
			sum[i] += add;
			sum[i] %= mod;
		}
	}
	//REP(i,v1.size()) cout<<i<<' '<<sum[i]<<endl;

	FOR(i,1,v2.size())if(v2[i]){
		res += v2[i] * ll(sum[i-1]);
		//cout<<"add "<<i<<' '<<v2[i]<<" "<< ll(sum[i-1])<<endl;
		res %= mod;
	}
//	cout<<res<<' '<<num()<<endl;
	cout<<res<<endl;

#ifdef LocalHost
	cerr<<endl<<endl<<"TIME: "<<clock()<<endl;
#endif
    return 0;
}


#pragma comment(linker, "/STACK:65777216")

#include <algorithm>
#include <iostream>
#include <string>
#include<sstream>
#include<string.h>
#include <cstdio>
#include <cassert>
#include <complex>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include<stack>
#include <set>
#include <map>
#include<ctime>
#include<list>

using namespace std;

typedef long long ll;
typedef unsigned long ull;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;

#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define SORT(v) sort((v).begin(),(v).end())
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back

const int mod = 1000000007;

int n,k;
char s[1111111];
char t[1111111];
vi v1,v2;

int sum[1111111];
vi tmp;

int tp[1111111];
int w[1111111];
int q[1111111];
int sw[1111111];

vi solve(char *s){
	tmp.clear();
	tmp.resize(n, 0);
	CL(w,0);CL(sw,0);CL(q,0);
	int num = 0;
	REP(i,n){
		if(s[i]=='X') q[i]=1;
		if(i) q[i]+=q[i-1];
		if(s[i]=='B' || s[i]=='X') num++;
		else num = 0;

		if(num>=k){
			int pos = i - k;
			if(pos<0) tmp[i] = 1;
			else  tmp[i] = w[pos];
		}

		w[i] = 0;
		if(s[i]=='W' || s[i]=='X'){
			if(i==0) w[i] = 1;
			else {
				if(i-1-k<-1){
					w[i] = tp[q[i-1]];
				}else{
					w[i] += sw[i-1] - (i-1-k>=0?sw[i-1-k]:0);
				}
				w[i]%=mod;
				if(w[i]<0) w[i]+=mod;
			}
		}

		sw[i] = w[i];
		if(i) sw[i]+=sw[i-1],sw[i]%=mod;

		//cout<<i<<" -> w[i] "<<w[i]<<"   sw[i] "<<sw[i]<<endl;

	}

	return tmp;
}

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

	tp[0]= 1;
	FOR(i,1,1111111) tp[i]=(tp[i-1]*2)%mod;
	cin>>n>>k;
	scanf(" %s",s);

	v1 = solve(s);
	//REP(i,v1.size()) cout<<v1[i]<<' ';puts("");

	REP(i,n) t[i] = s[n-1-i];
	REP(i,n) if(t[i]=='W') t[i]='B';
	else if(t[i]=='B') t[i]='W';
	v2 = solve(t);
	reverse(v2.begin(),v2.end());
	//REP(i,v2.size()) cout<<v2[i]<<' ';puts("");

	ll res = 0;
	REP(i,v1.size()){
		sum[i] = v1[i];
		if(i){
			int add = sum[i-1];
			if(s[i]=='X') add*=2,add%=mod;
			sum[i] += add;
			sum[i] %= mod;
		}
	}

	FOR(i,1,v2.size())if(v2[i]){
		res += v2[i] * ll(sum[i-1]);
		res %= mod;
	}
	cout<<res<<endl;

#ifdef LocalHost
	cerr<<endl<<endl<<"TIME: "<<clock()<<endl;
#endif
    return 0;
}


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

const int MAXN=1000000+10;
const int MODNUM=1000000000+7;

int lall[MAXN], lt[MAXN], lc[MAXN];
int rall[MAXN], rt[MAXN], rc[MAXN];
char s[MAXN];
int n, k;

int main() {
	scanf("%d%d%s", &n, &k, s);
	for(int i=n; i>=1; --i) s[i]=s[i-1];

	lall[0]=1;
	for(int i=1; i<=n; ++i) lall[i]=(lall[i-1]*(s[i]=='X'?2:1))%MODNUM;
	for(int i=0; i<k; ++i) lc[i]=lt[i]=0;
	int cnt=0; for(int i=1; i<=k; ++i) cnt+=(s[i]=='W');
	lc[k]=lt[k]=(cnt==0);
	for(int i=k+1; i<=n; ++i) {
		cnt-=(s[i-k]=='W');
		cnt+=(s[i]=='W');
		if(cnt==0 && s[i-k]!='B') lc[i]=(lall[i-k-1]-lt[i-k-1]+MODNUM)%MODNUM;
			else lc[i]=0;
		lt[i]=(lt[i-1]*(s[i]=='X'?2:1)%MODNUM+lc[i])%MODNUM;
	}

	rall[n+1]=1;
	for(int i=n; i>=1; --i) rall[i]=(rall[i+1]*(s[i]=='X'?2:1))%MODNUM;
	for(int i=n+1; i>n-k+1; --i) rc[i]=rt[i]=0;
	cnt=0; for(int i=n; i>=n-k+1; --i) cnt+=(s[i]=='B');
	rc[n-k+1]=rt[n-k+1]=(cnt==0);
	for(int i=n-k; i>=1; --i) {
		cnt-=(s[i+k]=='B');
		cnt+=(s[i]=='B');
		if(cnt==0 && s[i+k]!='W') rc[i]=(rall[i+k+1]-rt[i+k+1]+MODNUM)%MODNUM;
			else rc[i]=0;
		rt[i]=(rt[i+1]*(s[i]=='X'?2:1)%MODNUM+rc[i])%MODNUM;
	}

	//for(int i=1; i<=n; ++i) printf("lc[%d]=%d lt[%d]=%d\n", i,lc[i],i,lt[i]);

	int ans=0;
	for(int i=1; i<n; ++i) ans=((long long)ans+(long long)lt[i]*(long long)rc[i+1])%MODNUM;
	printf("%d\n", ans);
	return 0;
}


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

const int MAXN=1000000+10;
const int MODNUM=1000000000+7;

int lall[MAXN], lt[MAXN], lc[MAXN];
int rall[MAXN], rt[MAXN], rc[MAXN];
char s[MAXN];
int n, k;

int main() {
	scanf("%d%d%s", &n, &k, s);
	for(int i=n; i>=1; --i) s[i]=s[i-1];

	lall[0]=1;
	for(int i=1; i<=n; ++i) lall[i]=(lall[i-1]*(s[i]=='X'?2:1))%MODNUM;
	for(int i=0; i<k; ++i) lc[i]=lt[i]=0;
	int cnt=0; for(int i=1; i<=k; ++i) cnt+=(s[i]=='W');
	lc[k]=lt[k]=(cnt==0);
	for(int i=k+1; i<=n; ++i) {
		cnt-=(s[i-k]=='W');
		cnt+=(s[i]=='W');
		if(cnt==0 && s[i-k]!='B') lc[i]=(lall[i-k-1]-lt[i-k-1]+MODNUM)%MODNUM;
			else lc[i]=0;
		lt[i]=(lt[i-1]*(s[i]=='X'?2:1)+lc[i])%MODNUM;
	}

	rall[n+1]=1;
	for(int i=n; i>=1; --i) rall[i]=(rall[i+1]*(s[i]=='X'?2:1))%MODNUM;
	for(int i=n+1; i>n-k+1; --i) rc[i]=rt[i]=0;
	cnt=0; for(int i=n; i>=n-k+1; --i) cnt+=(s[i]=='B');
	rc[n-k+1]=rt[n-k+1]=(cnt==0);
	for(int i=n-k; i>=1; --i) {
		cnt-=(s[i+k]=='B');
		cnt+=(s[i]=='B');
		if(cnt==0 && s[i+k]!='W') rc[i]=(rall[i+k+1]-rt[i+k+1]+MODNUM)%MODNUM;
			else rc[i]=0;
		rt[i]=(rt[i+1]*(s[i]=='X'?2:1)+rc[i])%MODNUM;
	}

	//for(int i=1; i<=n; ++i) printf("lc[%d]=%d lt[%d]=%d\n", i,lc[i],i,lt[i]);

	int ans=0;
	for(int i=1; i<n; ++i) ans=((long long)ans+(long long)lt[i]*(long long)rc[i+1])%MODNUM;
	printf("%d\n", ans);
	return 0;
}


#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <sstream>
#include <cstddef>
#include <algorithm>
#include <utility>
#include <iterator>
#include <numeric>
#include <list>
#include <complex>
#include <cstdio>
#include <climits>
#include <iostream>
#include <fstream>

/*** TEMPLATE CODE STARTS HERE ***/

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef complex<double> pnt;
typedef pair<int, int> pii;

#define RA(x) (x).begin(), (x).end()
#define FE(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define SZ(x) ((int) (x).size())

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

static void redirect(int argc, const char **argv)
{
    if (argc > 1)
    {
        static filebuf f;
        f.open(argv[1], ios::in);
        cin.rdbuf(&f);
        if (!cin)
        {
            cerr << "Failed to open '" << argv[1] << "'" << endl;
            exit(1);
        }
    }

    if (argc > 2)
    {
        static filebuf f;
        f.open(argv[2], ios::out | ios::trunc);
        cout.rdbuf(&f);
        if (!cout)
        {
            cerr << "Failed to open '" << argv[2] << "'" << endl;
        }
    }
}

/*** TEMPLATE CODE ENDS HERE */

static ll power2[1000001];

#define MOD 1000000007
static vector<ll> ways(const string &s, char b, char w, int K)
{
    int N = SZ(s);
    vector<int> sumB(N + 1), sumX(N + 1), sumW(N + 1);
    vector<ll> ans(N + 1);
    vector<ll> asum(N + 1);
    for (int i = 1; i <= N; i++)
    {
        sumB[i] = sumB[i - 1];
        sumW[i] = sumW[i - 1];
        sumX[i] = sumX[i - 1];
        if (s[i - 1] == b)
            sumB[i]++;
        else if (s[i - 1] == w)
            sumW[i]++;
        else
            sumX[i]++;

        ans[i] = 0;
        if (i >= K)
        {
            if (sumW[i - K] == sumW[i])
            {
                if (i == K)
                    ans[i] = 1;
                else if (s[i - K - 1] != b)
                {
                    ans[i] = (power2[sumX[i - K - 1]] - asum[i - K - 1]) % MOD;
                }
            }
            if (s[i - 1] == 'X')
                asum[i] = (asum[i - 1] * 2 + ans[i]) % MOD;
            else
                asum[i] = (asum[i - 1] + ans[i]) % MOD;
        }
    }
    return ans;
}

int main(int argc, const char **argv)
{
    redirect(argc, argv);

    int N, K;
    string s;
    cin >> N >> K;
    cin >> s;

    power2[0] = 1;
    for (int i = 1; i <= N; i++)
        power2[i] = (power2[i - 1] * 2) % MOD;

    vector<ll> L = ways(s, 'B', 'W', K);
    reverse(RA(s));
    vector<ll> R = ways(s, 'W', 'B', K);
    reverse(RA(s));
    ll sumL = 0;
    ll ans = 0;
    for (int i = K; i + K <= N; i++)
    {
        if (s[i - 1] == 'X')
            sumL = (2 * sumL) % MOD;
        sumL = (sumL + L[i]) % MOD;
        ans = (ans + sumL * R[N - i]) % MOD;
    }
    if (ans < 0) ans += MOD;
    cout << ans << '\n';

    return 0;
}


#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <sstream>
#include <cstddef>
#include <algorithm>
#include <utility>
#include <iterator>
#include <numeric>
#include <list>
#include <complex>
#include <cstdio>
#include <climits>
#include <iostream>
#include <fstream>

/*** TEMPLATE CODE STARTS HERE ***/

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef complex<double> pnt;
typedef pair<int, int> pii;

#define RA(x) (x).begin(), (x).end()
#define FE(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define SZ(x) ((int) (x).size())

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

static void redirect(int argc, const char **argv)
{
    if (argc > 1)
    {
        static filebuf f;
        f.open(argv[1], ios::in);
        cin.rdbuf(&f);
        if (!cin)
        {
            cerr << "Failed to open '" << argv[1] << "'" << endl;
            exit(1);
        }
    }

    if (argc > 2)
    {
        static filebuf f;
        f.open(argv[2], ios::out | ios::trunc);
        cout.rdbuf(&f);
        if (!cout)
        {
            cerr << "Failed to open '" << argv[2] << "'" << endl;
        }
    }
}

/*** TEMPLATE CODE ENDS HERE */

static ll power2[1000001];

#define MOD 1000000009
static vector<ll> ways(const string &s, char b, char w, int K)
{
    int N = SZ(s);
    vector<int> sumB(N + 1), sumX(N + 1), sumW(N + 1);
    vector<ll> ans(N + 1);
    vector<ll> asum(N + 1);
    for (int i = 1; i <= N; i++)
    {
        sumB[i] = sumB[i - 1];
        sumW[i] = sumW[i - 1];
        sumX[i] = sumX[i - 1];
        if (s[i - 1] == b)
            sumB[i]++;
        else if (s[i - 1] == w)
            sumW[i]++;
        else
            sumX[i]++;

        ans[i] = 0;
        if (i >= K)
        {
            if (sumW[i - K] == sumW[i])
            {
                if (i == K)
                    ans[i] = 1;
                else if (s[i - K - 1] != b)
                {
                    ans[i] = (power2[sumX[i - K - 1]] - asum[i - K - 1]) % MOD;
                }
            }
            if (s[i - 1] == 'X')
                asum[i] = (asum[i - 1] * 2 + ans[i]) % MOD;
            else
                asum[i] = (asum[i - 1] + ans[i]) % MOD;
        }
    }
    return ans;
}

int main(int argc, const char **argv)
{
    redirect(argc, argv);

    int N, K;
    string s;
    cin >> N >> K;
    cin >> s;

    power2[0] = 1;
    for (int i = 1; i <= N; i++)
        power2[i] = (power2[i - 1] * 2) % MOD;

    vector<ll> L = ways(s, 'B', 'W', K);
    reverse(RA(s));
    vector<ll> R = ways(s, 'W', 'B', K);
    reverse(RA(s));
    ll sumL = 0;
    ll ans = 0;
    for (int i = K; i + K <= N; i++)
    {
        if (s[i - 1] == 'X')
            sumL = (2 * sumL) % MOD;
        sumL = (sumL + L[i]) % MOD;
        ans = (ans + sumL * R[N - i]) % MOD;
    }
    if (ans < 0) ans += MOD;
    cout << ans << '\n';

    return 0;
}


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

using namespace std;

const int MaxN=1<<20;
const int MOD=1000000007;

int n,k;
char s[MaxN];
int sB[MaxN],sW[MaxN],sX[MaxN];

long long GB[MaxN],GW[MaxN];
long long FBB[MaxN],FBW[MaxN],FWB[MaxN],FWW[MaxN];

void solve_B()
{
	FBW[0]=1;
	for (int i=1;i<=n;++i)
	{
		if (s[i]=='W')
		{
			FBW[i]=(FBB[i-1]+FBW[i-1])%MOD;
			continue;
		}
		if (s[i]=='B')
		{
			FBB[i]=(FBB[i-1]+FBW[i-1])%MOD;
		}
		else
		{
			FBW[i]=(FBB[i-1]+FBW[i-1])%MOD;
			FBB[i]=(FBB[i-1]+FBW[i-1])%MOD;
		}
		if (i-k+1>=1)
		{
			if (sB[i]+sX[i]-sB[i-k]-sX[i-k]==k)
			{
				FBB[i]=(FBB[i]-FBW[i-k]+MOD)%MOD;
			}
		}
	}
	for (int i=1;i<=n;++i)
	{
		if (i<k) continue;
		if (sB[i]+sX[i]-sB[i-k]-sX[i-k]<k) continue;
		if (s[i-k]!='B')
			if (i-k-1<0)
				GB[i]=1;
			else
				GB[i]=FBW[i-k];
	}
}

void solve_W()
{
	FWB[n+1]=1;
	for (int i=n;i>=1;--i)
	{
		if (s[i]=='B')
		{
			FWB[i]=(FWB[i+1]+FWW[i+1])%MOD;
			continue;
		}
		if (s[i]=='W')
		{
			FWW[i]=(FWB[i+1]+FWW[i+1])%MOD;
		}
		else
		{
			FWB[i]=(FWB[i+1]+FWW[i+1])%MOD;
			FWW[i]=(FWB[i+1]+FWW[i+1])%MOD;
		}
		if (i+k-1<=n)
		{
			if (sW[i+k-1]+sX[i+k-1]-sW[i-1]-sX[i-1]==k)
			{
				FWW[i]=(FWW[i]-FWB[i+k]+MOD)%MOD;
			}
		}
	}
	for (int i=n;i>=1;--i)
	{
		if (i+k-1>n) continue;
		if (sW[i+k-1]+sX[i+k-1]-sW[i-1]-sX[i-1]<k) continue;
		if (s[i+k]!='W')
			if (i+k+1>n+1)
				GW[i]=1;
			else
				GW[i]=FWB[i+k];
	}
}

int main()
{
	scanf("%d%d%s",&n,&k,s+1);
	for (int i=1;i<=n;++i)
	{
		sB[i]=sB[i-1]+(s[i]=='B');
		sW[i]=sW[i-1]+(s[i]=='W');
		sX[i]=sX[i-1]+(s[i]=='X');
	}
	solve_B();
	solve_W();
	for (int i=n;i>=1;--i)
	{
		GW[i]+=GW[i+1];
		if (s[i]=='X')
			GW[i]+=GW[i+1];
		GW[i]%=MOD;
	}
	long long ans=0;
	for (int i=1;i<=n;++i)
		(ans+=(long long)GB[i]*GW[i+1])%=MOD;
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define TASKNAME "text"
#define pb push_back
#define mp make_pair
#define EPS (1E-9)
#define INF ((int)1E9)
#define sqr(x) ((x) * (x))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())

const int maxn = (int)1e6;
char s[maxn + 1];
int dW[maxn + 1], dB[maxn + 1];
int cntW[maxn + 1], cntB[maxn + 1];

const int MOD = (int)1e9 + 7;

inline int mmod(int x) {
	return x >= MOD ? x - MOD : x < 0 ? x + MOD : x;
}

int main() {
	#ifdef DEBUG
		freopen(TASKNAME".in", "r", stdin);
		freopen(TASKNAME".out", "w", stdout);
	#endif

	int n, k;
	while (scanf("%d%d%s", &n, &k, s) >= 1) {
		dW[0] = 1;
		for (int i = 0, sum = dW[0]; i < n; i++) {
			dW[i + 1] = s[i] == 'B' ? 0 : sum;
			if (i >= k - 1)
				sum -= dW[i - k + 1];
			if (s[i] == 'W')
				sum = 0;
			sum += dW[i + 1];
			sum = mmod(sum);
		}

		dB[n] = 1;
		for (int i = n - 1, sum = dB[n]; i >= 0; i--) {
			dB[i] = s[i] == 'W' ? 0 : sum;
			if (i + k <= n)
				sum -= dB[i + k];
			if (s[i] == 'B')
				sum = 0;
			sum += dB[i];
			sum = mmod(sum);
		}

		cntW[0] = cntB[0] = 0;
		for (int i = 0; i < n; i++) {
			cntW[i + 1] = cntW[i] + (s[i] == 'W');
			cntB[i + 1] = cntB[i] + (s[i] == 'B');
		}

		/*
		for (int i = 0; i <= n; i++)
			eprintf("%d%c", dW[i], " \n"[i == n]);
		for (int i = 0; i <= n; i++)
			eprintf("%d%c", dB[i], " \n"[i == n]);
		*/
		int ans = 0;
		for (int l = n - 2 * k, countr = 0; l >= 0; l--) {
			if (s[l + k] == 'X')
				countr = mmod(2 * countr);
			if (cntB[l + 2 * k] - cntB[l + k] == 0)
				countr = mmod(countr + dB[l + 2 * k]);

			if (cntW[l + k] - cntW[l] == 0)
				ans = (ans + (ll)dW[l] * countr) % MOD;
		}

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


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

using namespace std;

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define TASKNAME "text"
#define pb push_back
#define mp make_pair
#define EPS (1E-9)
#define INF ((int)1E9)
#define sqr(x) ((x) * (x))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())

const int maxn = (int)1e6;
char s[maxn + 1];
int dW[maxn + 1], dB[maxn + 1];
int cntW[maxn + 1], cntB[maxn + 1];

const int MOD = (int)1e9 + 7;

inline int mmod(int x) {
	return x >= MOD ? x - MOD : x < 0 ? x + MOD : x;
}

int main() {
	#ifdef DEBUG
		freopen(TASKNAME".in", "r", stdin);
		freopen(TASKNAME".out", "w", stdout);
	#endif

	int n, k;
	while (scanf("%d%d%s", &n, &k, s) >= 1) {
		dW[0] = 1;
		for (int i = 0, sum = dW[0], needkill = -1; i < n; i++) {
			dW[i + 1] = (s[i] == 'B') ? 0 : sum;
			if (i >= k - 1 && needkill <= i)
				sum -= dW[i - k + 1];
			if (s[i] == 'W')
				sum = 0, needkill = i + k;
			sum += dW[i + 1];
			sum = mmod(sum);
		}

		dB[n] = 1;
		for (int i = n - 1, sum = dB[n], needkill = n; i >= 0; i--) {
			dB[i] = (s[i] == 'W') ? 0 : sum;
			if (i + k <= n && needkill >= i)
				sum -= dB[i + k];
			if (s[i] == 'B')
				sum = 0, needkill = i - k;
			sum += dB[i];
			sum = mmod(sum);
		}

		cntW[0] = cntB[0] = 0;
		for (int i = 0; i < n; i++) {
			cntW[i + 1] = cntW[i] + (s[i] == 'W');
			cntB[i + 1] = cntB[i] + (s[i] == 'B');
		}

		/*
		for (int i = 0; i <= n; i++)
			eprintf("%d%c", dW[i], " \n"[i == n]);
		for (int i = 0; i <= n; i++)
			eprintf("%d%c", dB[i], " \n"[i == n]);
		*/
		int ans = 0;
		for (int l = n - 2 * k, countr = 0; l >= 0; l--) {
			if (s[l + k] == 'X')
				countr = mmod(2 * countr);
			if (cntB[l + 2 * k] - cntB[l + k] == 0)
				countr = mmod(countr + dB[l + 2 * k]);

			if (cntW[l + k] - cntW[l] == 0) {
				ans = (ans + (ll)dW[l] * countr) % MOD;
				//eprintf("l = %d, ans = %d\n", l, ans);
			}
		}

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


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

using namespace std;

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define TASKNAME "text"
#define pb push_back
#define mp make_pair
#define EPS (1E-9)
#define INF ((int)1E9)
#define sqr(x) ((x) * (x))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())

const int maxn = (int)1e6;
char s[maxn + 1];
int dW[maxn + 1], dB[maxn + 1];
int cntW[maxn + 1], cntB[maxn + 1];

const int MOD = (int)1e9 + 7;

inline int mmod(int x) {
	return x >= MOD ? x - MOD : x < 0 ? x + MOD : x;
}

int main() {
	#ifdef DEBUG
		freopen(TASKNAME".in", "r", stdin);
		freopen(TASKNAME".out", "w", stdout);
	#endif

	int n, k;
	while (scanf("%d%d%s", &n, &k, s) >= 1) {
		dW[0] = 1;
		for (int i = 0, sum = dW[0]; i < n; i++) {
			dW[i + 1] = s[i] == 'B' ? 0 : sum;
			if (i >= k - 1)
				sum -= dW[i - k + 1];
			if (s[i] == 'W')
				sum = 0;
			sum += dW[i + 1];
			sum = mmod(sum);
		}

		dB[n] = 1;
		for (int i = n - 1, sum = dB[n]; i >= 0; i--) {
			dB[i] = s[i] == 'W' ? 0 : sum;
			if (i + k <= n)
				sum -= dB[i + k];
			if (s[i] == 'B')
				sum = 0;
			sum += dB[i];
			sum = mmod(sum);
		}

		cntW[0] = cntB[0] = 0;
		for (int i = 0; i < n; i++) {
			cntW[i + 1] = cntW[i] + (s[i] == 'W');
			cntB[i + 1] = cntB[i] + (s[i] == 'B');
		}

		/*
		for (int i = 0; i <= n; i++)
			eprintf("%d%c", dW[i], " \n"[i == n]);
		for (int i = 0; i <= n; i++)
			eprintf("%d%c", dB[i], " \n"[i == n]);
		*/
		int ans = 0;
		for (int l = n - 2 * k, countr = 0; l >= 0; l--) {
			if (s[l + k] == 'X')
				countr = mmod(2 * countr);
			if (cntB[l + 2 * k] - cntB[l + k] == 0)
				countr = mmod(countr + dB[l + 2 * k]);

			if (cntW[l + k] - cntW[l] == 0)
				ans = (ans + (ll)dW[l] * countr);
		}

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


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

using namespace std;

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

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

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

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

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

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

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

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

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