S=input()
K=int(input())
import copy
num=1
liS=[]

for i in range(len(S)-1):
    if S[i]==S[i+1]:
        num+=1
    else:
        liS.append(num)
        num=1
liS.append(num)



liSR=copy.copy(liS)
liSR[0]+=liSR[-1]
del liSR[-1]



if liSR!=[] and S[0]==S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    for k in range(len(liSR)):
        liSR[k]=liSR[k]//2

    print(sum(liSR)*(K-1)+sum(liS))

elif liSR!=[] and S[0]!=S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    print(sum(liS)*K)

else:
    print((sum(liS)*K)//2)
 S=input() S input() input K=int(input()) K int(input()) int input() input import copy copy num=1 num 1 liS=[] liS [] for i in range(len(S)-1):
    if S[i]==S[i+1]:
        num+=1
    else:
        liS.append(num)
        num=1 i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i]==S[i+1]:
        num+=1
    else:
        liS.append(num)
        num=1 S[i]==S[i+1] S[i] S i S[i+1] S i+1 i 1 num+=1 num 1 liS.append(num) liS.append liS append num num=1 num 1 liS.append(num) liS.append liS append num liSR=copy.copy(liS) liSR copy.copy(liS) copy.copy copy copy liS liSR[0]+=liSR[-1] liSR[0] liSR 0 liSR[-1] liSR -1 del liSR[-1] liSR[-1] liSR -1 if liSR!=[] and S[0]==S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    for k in range(len(liSR)):
        liSR[k]=liSR[k]//2

    print(sum(liSR)*(K-1)+sum(liS))

elif liSR!=[] and S[0]!=S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    print(sum(liS)*K)

else:
    print((sum(liS)*K)//2) liSR!=[] and S[0]==S[-1] liSR!=[] liSR [] S[0]==S[-1] S[0] S 0 S[-1] S -1 for j in range(len(liS)):
        liS[j]=liS[j]//2
     j range(len(liS)) range len(liS) len liS liS[j]=liS[j]//2 liS[j] liS j liS[j]//2 liS[j] liS j 2 for k in range(len(liSR)):
        liSR[k]=liSR[k]//2

     k range(len(liSR)) range len(liSR) len liSR liSR[k]=liSR[k]//2 liSR[k] liSR k liSR[k]//2 liSR[k] liSR k 2 print(sum(liSR)*(K-1)+sum(liS)) print sum(liSR)*(K-1)+sum(liS) sum(liSR)*(K-1) sum(liSR) sum liSR K-1 K 1 sum(liS) sum liS elif liSR!=[] and S[0]!=S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    print(sum(liS)*K) liSR!=[] and S[0]!=S[-1] liSR!=[] liSR [] S[0]!=S[-1] S[0] S 0 S[-1] S -1 for j in range(len(liS)):
        liS[j]=liS[j]//2
     j range(len(liS)) range len(liS) len liS liS[j]=liS[j]//2 liS[j] liS j liS[j]//2 liS[j] liS j 2 print(sum(liS)*K) print sum(liS)*K sum(liS) sum liS K print((sum(liS)*K)//2) print (sum(liS)*K)//2 sum(liS)*K sum(liS) sum liS K 2 liSR=copy.copy(liS) copy.copy(liS) liSR num=1 1 num num+=1 1 num K=int(input()) int(input()) K num=1 1 num S=input() input() S liS=[] [] liS
S=input()
K=int(input())
import copy
num=1
liS=[]

for i in range(len(S)-1):
    if S[i]==S[i+1]:
        num+=1
    else:
        liS.append(num)
        num=1
liS.append(num)



liSR=copy.copy(liS)
liSR[0]+=liSR[-1]
del liSR[-1]



if liSR!=[] and S[0]==S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    for k in range(len(liSR)):
        liSR[k]=liSR[k]//2

    print(sum(liSR)*(K-1)+sum(liS))

elif liSR!=[] and S[0]!=S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    print(sum(liS)*K)

else:
    print((sum(liS)*K)//2)

