from copy import deepcopy

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

n = len(s)
if len(list(set(s))) == 1:
    print(n*k//2)
    exit()

n1 = 0
n2 = 0
s1 = deepcopy(s)
s2 = deepcopy(s) + deepcopy(s)

for i in range(n-1):
    if s1[i] == s1[i+1]:
        s1[i+1] = "?"
        n1 += 1

for i in range(2*n - 1):
    if s2[i] == s2[i+1]:
        s2[i+1] = "?"
        n2 += 1

d = n2 - n1

ans = n1 + d*(k-1)
print(ans) from copy import deepcopy s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s if len(list(set(s))) == 1:
    print(n*k//2)
    exit() len(list(set(s))) == 1 len(list(set(s))) len list(set(s)) list set(s) set s 1 print(n*k//2) print n*k//2 n*k n k 2 exit() exit n1 = 0 n1 0 n2 = 0 n2 0 s1 = deepcopy(s) s1 deepcopy(s) deepcopy s s2 = deepcopy(s) + deepcopy(s) s2 deepcopy(s) + deepcopy(s) deepcopy(s) deepcopy s deepcopy(s) deepcopy s for i in range(n-1):
    if s1[i] == s1[i+1]:
        s1[i+1] = "?"
        n1 += 1 i range(n-1) range n-1 n 1 if s1[i] == s1[i+1]:
        s1[i+1] = "?"
        n1 += 1 s1[i] == s1[i+1] s1[i] s1 i s1[i+1] s1 i+1 i 1 s1[i+1] = "?" s1[i+1] s1 i+1 i 1 "?" n1 += 1 n1 1 for i in range(2*n - 1):
    if s2[i] == s2[i+1]:
        s2[i+1] = "?"
        n2 += 1 i range(2*n - 1) range 2*n - 1 2*n 2 n 1 if s2[i] == s2[i+1]:
        s2[i+1] = "?"
        n2 += 1 s2[i] == s2[i+1] s2[i] s2 i s2[i+1] s2 i+1 i 1 s2[i+1] = "?" s2[i+1] s2 i+1 i 1 "?" n2 += 1 n2 1 d = n2 - n1 d n2 - n1 n2 n1 ans = n1 + d*(k-1) ans n1 + d*(k-1) n1 d*(k-1) d k-1 k 1 print(ans) print ans n2 = 0 0 n2 n2 += 1 1 n2 k = int(input()) int(input()) k n = len(s) len(s) n s2 = deepcopy(s) + deepcopy(s) deepcopy(s) + deepcopy(s) s2 s = list(input()) list(input()) s n1 = 0 0 n1 n1 += 1 1 n1 d = n2 - n1 n2 - n1 d s1 = deepcopy(s) deepcopy(s) s1 ans = n1 + d*(k-1) n1 + d*(k-1) ans
from copy import deepcopy

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

n = len(s)
if len(list(set(s))) == 1:
    print(n*k//2)
    exit()

n1 = 0
n2 = 0
s1 = deepcopy(s)
s2 = deepcopy(s) + deepcopy(s)

for i in range(n-1):
    if s1[i] == s1[i+1]:
        s1[i+1] = "?"
        n1 += 1

for i in range(2*n - 1):
    if s2[i] == s2[i+1]:
        s2[i+1] = "?"
        n2 += 1

d = n2 - n1

ans = n1 + d*(k-1)
print(ans)