S=input()
K=int(input())

i=1
count1=0
while i<len(S):
    if S[i]==S[i-1]:
        count1+=1
        i+=1
    i+=1

ss=S*2
i=1
count2=0
while i<len(ss):
    if ss[i]==ss[i-1]:
        count2+=1
        i+=1
    i+=1

if 2*count1+1==count2 and len(set(S))!=1:
    print(K*count1+(K-1))
else:
    print(K*count2//2) S=input() S input() input K=int(input()) K int(input()) int input() input i=1 i 1 count1=0 count1 0 while i<len(S):
    if S[i]==S[i-1]:
        count1+=1
        i+=1
    i+=1 i<len(S) i len(S) len S if S[i]==S[i-1]:
        count1+=1
        i+=1
     S[i]==S[i-1] S[i] S i S[i-1] S i-1 i 1 count1+=1 count1 1 i+=1 i 1 i+=1 i 1 ss=S*2 ss S*2 S 2 i=1 i 1 count2=0 count2 0 while i<len(ss):
    if ss[i]==ss[i-1]:
        count2+=1
        i+=1
    i+=1 i<len(ss) i len(ss) len ss if ss[i]==ss[i-1]:
        count2+=1
        i+=1
     ss[i]==ss[i-1] ss[i] ss i ss[i-1] ss i-1 i 1 count2+=1 count2 1 i+=1 i 1 i+=1 i 1 if 2*count1+1==count2 and len(set(S))!=1:
    print(K*count1+(K-1))
else:
    print(K*count2//2) 2*count1+1==count2 and len(set(S))!=1 2*count1+1==count2 2*count1+1 2*count1 2 count1 1 count2 len(set(S))!=1 len(set(S)) len set(S) set S 1 print(K*count1+(K-1)) print K*count1+(K-1) K*count1 K count1 K-1 K 1 print(K*count2//2) print K*count2//2 K*count2 K count2 2 i+=1 1 i ss=S*2 S*2 ss i=1 1 i count1=0 0 count1 count1+=1 1 count1 i+=1 1 i count2=0 0 count2 i=1 1 i i+=1 1 i S=input() input() S K=int(input()) int(input()) K count2+=1 1 count2 i+=1 1 i
S=input()
K=int(input())

i=1
count1=0
while i<len(S):
    if S[i]==S[i-1]:
        count1+=1
        i+=1
    i+=1

ss=S*2
i=1
count2=0
while i<len(ss):
    if ss[i]==ss[i-1]:
        count2+=1
        i+=1
    i+=1

if 2*count1+1==count2 and len(set(S))!=1:
    print(K*count1+(K-1))
else:
    print(K*count2//2)