S=list(input())
K=int(input())
cnt=cnt2=0
s=S*2
if len(set(S))==1:
    print(len(S)*K//2);exit()
for i in range(len(S)-1):
    if S[i+1]==S[i]:
        cnt+=1
        S[i+1]="#"
for i in range(len(s)-1):
    if s[i+1]==s[i]:
        cnt2+=1
        s[i+1]="#"
print(cnt+(cnt2-cnt)*(K-1)) S=list(input()) S list(input()) list input() input K=int(input()) K int(input()) int input() input cnt=cnt2=0 cnt 0 =cnt2=0 cnt2 0 s=S*2 s S*2 S 2 if len(set(S))==1:
    print(len(S)*K//2);exit() len(set(S))==1 len(set(S)) len set(S) set S 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 exit() exit for i in range(len(S)-1):
    if S[i+1]==S[i]:
        cnt+=1
        S[i+1]="#" i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i+1]==S[i]:
        cnt+=1
        S[i+1]="#" S[i+1]==S[i] S[i+1] S i+1 i 1 S[i] S i cnt+=1 cnt 1 S[i+1]="#" S[i+1] S i+1 i 1 "#" for i in range(len(s)-1):
    if s[i+1]==s[i]:
        cnt2+=1
        s[i+1]="#" i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i+1]==s[i]:
        cnt2+=1
        s[i+1]="#" s[i+1]==s[i] s[i+1] s i+1 i 1 s[i] s i cnt2+=1 cnt2 1 s[i+1]="#" s[i+1] s i+1 i 1 "#" print(cnt+(cnt2-cnt)*(K-1)) print cnt+(cnt2-cnt)*(K-1) cnt (cnt2-cnt)*(K-1) cnt2-cnt cnt2 cnt K-1 K 1 K=int(input()) int(input()) K cnt=cnt2=0 0 cnt cnt2=0 0 cnt2 cnt2+=1 1 cnt2 s=S*2 S*2 s cnt+=1 1 cnt S=list(input()) list(input()) S
S=list(input())
K=int(input())
cnt=cnt2=0
s=S*2
if len(set(S))==1:
    print(len(S)*K//2);exit()
for i in range(len(S)-1):
    if S[i+1]==S[i]:
        cnt+=1
        S[i+1]="#"
for i in range(len(s)-1):
    if s[i+1]==s[i]:
        cnt2+=1
        s[i+1]="#"
print(cnt+(cnt2-cnt)*(K-1))