S = list(input())
K = int(input())
 
ans = 0
#２つ並べて一般性を確かめる
S2 = S*2

for i in range(1,len(S2)):
    if S2[i-1]== S2[i]:
        S2[i] = '@'
        #2回目以降はk-1回任意の@へ直す
        if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1
            
if len(set(S)) ==1 and len(S)%2 !=0:
   ans = len(S)*(K//2)+(K%2==1)*(len(S)//2)
print(ans)  S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input ans = 0 ans 0 S2 = S*2 S2 S*2 S 2 for i in range(1,len(S2)):
    if S2[i-1]== S2[i]:
        S2[i] = '@'
        #2回目以降はk-1回任意の@へ直す
        if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1
             i range(1,len(S2)) range 1 len(S2) len S2 if S2[i-1]== S2[i]:
        S2[i] = '@'
        #2回目以降はk-1回任意の@へ直す
        if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1
             S2[i-1]== S2[i] S2[i-1] S2 i-1 i 1 S2[i] S2 i S2[i] = '@' S2[i] S2 i '@' if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1
             i>=len(S2)//2 i len(S2)//2 len(S2) len S2 2 ans+= K-1 ans K-1 K 1 ans+=1 ans 1 if len(set(S)) ==1 and len(S)%2 !=0:
   ans = len(S)*(K//2)+(K%2==1)*(len(S)//2) len(set(S)) ==1 and len(S)%2 !=0 len(set(S)) ==1 len(set(S)) len set(S) set S 1 len(S)%2 !=0 len(S)%2 len(S) len S 2 0 ans = len(S)*(K//2)+(K%2==1)*(len(S)//2) ans len(S)*(K//2)+(K%2==1)*(len(S)//2) len(S)*(K//2) len(S) len S K//2 K 2 (K%2==1)*(len(S)//2) K%2==1 K%2 K 2 1 len(S)//2 len(S) len S 2 print(ans) print ans S2 = S*2 S*2 S2 ans+= K-1 K-1 ans ans+=1 1 ans ans = 0 0 ans K = int(input()) int(input()) K ans = len(S)*(K//2)+(K%2==1)*(len(S)//2) len(S)*(K//2)+(K%2==1)*(len(S)//2) ans S = list(input()) list(input()) S
S = list(input())
K = int(input())
 
ans = 0
#２つ並べて一般性を確かめる
S2 = S*2

for i in range(1,len(S2)):
    if S2[i-1]== S2[i]:
        S2[i] = '@'
        #2回目以降はk-1回任意の@へ直す
        if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1
            
if len(set(S)) ==1 and len(S)%2 !=0:
   ans = len(S)*(K//2)+(K%2==1)*(len(S)//2)
print(ans) 