from collections import Counter

s = list(input())
k = int(input())

ans = 0
s_d = s*2
for i in range(1,len(s_d)):
    if s_d[i-1]==s_d[i]:
        s_d[i] = '_'
        if i>=len(s_d)//2:
            ans+=k-1
        else:
            ans+=1
s_s = set(s)
if len(s_s)==1 and len(s)%2!=0:
    ans = len(s)*(k//2)+(k%2==1)*(len(s)//2)
print(ans)  from collections import Counter s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input ans = 0 ans 0 s_d = s*2 s_d s*2 s 2 for i in range(1,len(s_d)):
    if s_d[i-1]==s_d[i]:
        s_d[i] = '_'
        if i>=len(s_d)//2:
            ans+=k-1
        else:
            ans+=1 i range(1,len(s_d)) range 1 len(s_d) len s_d if s_d[i-1]==s_d[i]:
        s_d[i] = '_'
        if i>=len(s_d)//2:
            ans+=k-1
        else:
            ans+=1 s_d[i-1]==s_d[i] s_d[i-1] s_d i-1 i 1 s_d[i] s_d i s_d[i] = '_' s_d[i] s_d i '_' if i>=len(s_d)//2:
            ans+=k-1
        else:
            ans+=1 i>=len(s_d)//2 i len(s_d)//2 len(s_d) len s_d 2 ans+=k-1 ans k-1 k 1 ans+=1 ans 1 s_s = set(s) s_s set(s) set s if len(s_s)==1 and len(s)%2!=0:
    ans = len(s)*(k//2)+(k%2==1)*(len(s)//2) len(s_s)==1 and len(s)%2!=0 len(s_s)==1 len(s_s) len s_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 ans+=1 1 ans s = list(input()) list(input()) s s_s = set(s) set(s) s_s s_d = s*2 s*2 s_d ans+=k-1 k-1 ans k = int(input()) int(input()) k ans = 0 0 ans ans = len(s)*(k//2)+(k%2==1)*(len(s)//2) len(s)*(k//2)+(k%2==1)*(len(s)//2) ans
from collections import Counter

s = list(input())
k = int(input())

ans = 0
s_d = s*2
for i in range(1,len(s_d)):
    if s_d[i-1]==s_d[i]:
        s_d[i] = '_'
        if i>=len(s_d)//2:
            ans+=k-1
        else:
            ans+=1
s_s = set(s)
if len(s_s)==1 and len(s)%2!=0:
    ans = len(s)*(k//2)+(k%2==1)*(len(s)//2)
print(ans) 