S = [i for i in input()]
K = int(input())
ans = 0
s = S*2
for i in range(1,len(s)):
    if s[i-1] == s[i]:
        s[i] = "_"
        if i >= len(s)//2:
            ans += K-1
        else:
            ans += 1
kazu = set(S)
if len(kazu) == 1 and len(S) % 2 != 0:
  ans = len(S) * (K//2) + (K%2==1) * (len(S)//2)
print(ans) i for i in input() for i in input() i input() input for i in input() i S = [i for i in input()] S [i for i in input()] K = int(input()) K int(input()) int input() input ans = 0 ans 0 s = S*2 s S*2 S 2 for i in range(1,len(s)):
    if s[i-1] == s[i]:
        s[i] = "_"
        if i >= len(s)//2:
            ans += K-1
        else:
            ans += 1 i range(1,len(s)) range 1 len(s) len s if s[i-1] == s[i]:
        s[i] = "_"
        if i >= len(s)//2:
            ans += K-1
        else:
            ans += 1 s[i-1] == s[i] s[i-1] s i-1 i 1 s[i] s i s[i] = "_" s[i] s i "_" if i >= len(s)//2:
            ans += K-1
        else:
            ans += 1 i >= len(s)//2 i len(s)//2 len(s) len s 2 ans += K-1 ans K-1 K 1 ans += 1 ans 1 kazu = set(S) kazu set(S) set S if len(kazu) == 1 and len(S) % 2 != 0:
  ans = len(S) * (K//2) + (K%2==1) * (len(S)//2) len(kazu) == 1 and len(S) % 2 != 0 len(kazu) == 1 len(kazu) len kazu 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 s = S*2 S*2 s ans = 0 0 ans S = [i for i in input()] [i for i in input()] S kazu = set(S) set(S) kazu ans += K-1 K-1 ans ans = len(S) * (K//2) + (K%2==1) * (len(S)//2) len(S) * (K//2) + (K%2==1) * (len(S)//2) ans K = int(input()) int(input()) K ans += 1 1 ans
S = [i for i in input()]
K = int(input())
ans = 0
s = S*2
for i in range(1,len(s)):
    if s[i-1] == s[i]:
        s[i] = "_"
        if i >= len(s)//2:
            ans += K-1
        else:
            ans += 1
kazu = set(S)
if len(kazu) == 1 and len(S) % 2 != 0:
  ans = len(S) * (K//2) + (K%2==1) * (len(S)//2)
print(ans)