Solve in Python:
There are $n$ chips arranged in a circle, numbered from $1$ to $n$. 

Initially each chip has black or white color. Then $k$ iterations occur. During each iteration the chips change their colors according to the following rules. For each chip $i$, three chips are considered: chip $i$ itself and two its neighbours. If the number of white chips among these three is greater than the number of black chips among these three chips, then the chip $i$ becomes white. Otherwise, the chip $i$ becomes black. 

Note that for each $i$ from $2$ to $(n - 1)$ two neighbouring chips have numbers $(i - 1)$ and $(i + 1)$. The neighbours for the chip $i = 1$ are $n$ and $2$. The neighbours of $i = n$ are $(n - 1)$ and $1$.

The following picture describes one iteration with $n = 6$. The chips $1$, $3$ and $4$ are initially black, and the chips $2$, $5$ and $6$ are white. After the iteration $2$, $3$ and $4$ become black, and $1$, $5$ and $6$ become white.

 [Image] 

Your task is to determine the color of each chip after $k$ iterations.


-----Input-----

The first line contains two integers $n$ and $k$ $(3 \le n \le 200\,000, 1 \le k \le 10^{9})$ — the number of chips and the number of iterations, respectively.

The second line contains a string consisting of $n$ characters "W" and "B". If the $i$-th character is "W", then the $i$-th chip is white initially. If the $i$-th character is "B", then the $i$-th chip is black initially.


-----Output-----

Print a string consisting of $n$ characters "W" and "B". If after $k$ iterations the $i$-th chip is white, then the $i$-th character should be "W". Otherwise the $i$-th character should be "B".


-----Examples-----
Input
6 1
BWBBWW

Output
WBBBWW

Input
7 3
WBWBWBW

Output
WWWWWWW

Input
6 4
BWBWBW

Output
BWBWBW



-----Note-----

The first example is described in the statement.

The second example: "WBWBWBW" $\rightarrow$ "WWBWBWW" $\rightarrow$ "WWWBWWW" $\rightarrow$ "WWWWWWW". So all chips become white.

The third example: "BWBWBW" $\rightarrow$ "WBWBWB" $\rightarrow$ "BWBWBW"...
import sys
input = sys.stdin.readline

n,k=list(map(int,input().split()))
S=input().strip()

ANS=["?"]*n

for i in range(n-1):
    if S[i]=="B":
        if S[i-1]=="B" or S[i+1]=="B":
            ANS[i]="B"

    else:
        if S[i-1]=="W" or S[i+1]=="W":
            ANS[i]="W"

if S[n-1]=="B":
    if S[n-2]=="B" or S[0]=="B":
        ANS[n-1]="B"

else:
    if S[n-2]=="W" or S[0]=="W":
        ANS[n-1]="W"


COMP=[]

count=1
now=ANS[0]

for i in range(1,n):
    if ANS[i]==ANS[i-1]:
        count+=1
    else:
        COMP.append([now,count])
        count=1
        now=ANS[i]

COMP.append([now,count])
hosei=0

if len(COMP)==1:
    if COMP[0][0]!="?":
        print(S)
    else:
        if k%2==0:
            print(S)
        else:
            ANS=[]
            for s in S:
                if s=="B":
                    ANS.append("W")
                else:
                    ANS.append("B")
            print("".join(ANS))
    return

if COMP[0][0]=="?" and COMP[-1][0]=="?":
    hosei=COMP[-1][1]
    COMP.pop()
    COMP[0][1]+=hosei

ANS2=[]

LEN=len(COMP)
if COMP[0][0]!="?":
    COMP.append(COMP[0])

for i in range(LEN):
    if COMP[i][0]!="?":
        ANS2.append(COMP[i])
    else:
        x=COMP[i][1]

        if x<=k*2:
            if COMP[i-1][0]==COMP[i+1][0]:
                ANS2.append([COMP[i-1][0],x])

            else:
                ANS2.append([COMP[i-1][0],x//2])
                ANS2.append([COMP[i+1][0],x//2])

        else:
            ANS2.append([COMP[i-1][0],k])
            ANS2.append(["?",x-2*k])
            ANS2.append([COMP[i+1][0],k])

#print(ANS2)
            
GOAL=[]
for x,y in ANS2:
    if x!="?":
        GOAL+=[x]*y
    else:
        if GOAL!=[]:
            if GOAL[-1]=="B":
                t=0
            else:
                t=1
        else:
            if ANS2[-1][0]=="B":
                t=0
            else:
                t=1

        for j in range(y):
            if j%2==0:
                if t==0:
                    GOAL.append("W")
                else:
            ...