Problem:
Score : 900 points

Problem Statement

Takahashi has a lot of peculiar devices.
These cylindrical devices receive balls from left and right.
Each device is in one of the two states A and B, and for each state, the device operates as follows:

When a device in state A receives a ball from either side (left or right), the device throws out the ball from the same side, then immediately goes into state B.

When a device in state B receives a ball from either side, the device throws out the ball from the other side, then immediately goes into state A.

The transition of the state of a device happens momentarily and always completes before it receives another ball.

Takahashi built a contraption by concatenating N of these devices. In this contraption,

A ball that was thrown out from the right side of the i-th device from the left (1 \leq i \leq N-1) immediately enters the (i+1)-th device from the left side.

A ball that was thrown out from the left side of the i-th device from the left (2 \leq i \leq N) immediately enters the (i-1)-th device from the right side.

The initial state of the i-th device from the left is represented by the i-th character in a string S.
From this situation, Takahashi performed the following K times: put a ball into the leftmost device from the left side, then wait until the ball comes out of the contraption from either end.
Here, it can be proved that the ball always comes out of the contraption after a finite time.
Find the state of each device after K balls are processed.

Constraints

1 \leq N \leq 200,000

1 \leq K \leq 10^9

|S|=N

Each character in S is either A or B.

Input

The input is given from Standard Input in the following format:

N K
S

Output

Print a string that represents the state of each device after K balls are processed.
The string must be N characters long, and the i-th character must correspond to the state of the i-th device from the left.

Sample Input 1

5 1
ABAAA

Sample Output 1

BBAAA

In this input, we put a ball into the leftmost device from the left side, then it is returned from the same place.

Sample Input 2

5 2
ABAAA

Sample Output 2

ABBBA

Sample Input 3

4 123456789
AABB

Sample Output 3

BABA

Solution in C++14 (Clang 3.8.0) (judge verdict: Accepted)

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 100000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

int A[MAX];
void sim(string& s)
{
	int p = 0;
	int d = 1;
	while (1)
	{
		if (p == -1 || p == SZ(s)) break;
		if (s[p] == 'A')
		{
			s[p] = 'B';
			d *= -1;
			p += d;
			continue;
		}
		else
		{
			s[p] = 'A';
			p += d;
		}
	}
}

void sim(string& s, int k)
{
	FOR(i, 0, k)
	{
		sim(s);
	}
}

void calc(string& s, int k)
{
	int rev = 0;
	int p = 0;
	int n = SZ(s);
	if (n == 1)
	{
		s[0] = ((s[0] - 'A') ^ (k & 1)) + 'A';
		return;
	}

	FOR(i, 0, n) A[i] = s[i] == 'B';

	FOR(i, 0, min(k, 4 * n + k % 2))
	{
		if (A[p] ^ rev == 0)
		{
			A[p] ^= 1;
			continue;
		}

		rev ^= 1;
		A[p] = rev;
		p++;
		if (p == n) p = 0;
	}

	FOR(k, 0, n)
	{
		int i = p + k;
		if (i >= n) i -= n;

		s[k] = (A[i] ^ rev) + 'A';
	}
}

string s;
int k, n;
void gen()
{
	n = rand() % 10 + 1;
	s.clear();
	FOR(i, 0, n)
	{
		s.push_back(rand() % 2 + 'A');
	}

	k = rand() % 10 + 1;
}

//#define TEST

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);

#ifdef TEST
	while (1)
	{
		gen();
		cout << s << " " << k << endl;
		string s1 = s;
		calc(s, k);
		sim(s1, k);
		if (s1 != s)
		{
			cout << "fail" << endl;
			cout << s << endl;
			cout << s1 << endl;
			return 0;
		}
	}
#else
	cin >> n >> k >> s;
	calc(s, k);
	cout << s << endl;
#endif

}