s = input()
k = int(input())
ans = 0
soui = 0
moji = s[0]

for i in range(1,len(s)):
    if s[i] == s[i-1] and soui == 0:
        ans += 1
        soui = 1
    elif soui == 1:
        soui = 0


flag = 0
a = 0
b = 0

while s[0] == s[a] and a != len(s)-1:
    a += 1

while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1:
    b += 1


if s[0] == s[len(s)-1]:
    flag = 1

for i in range(len(s)):
    if moji != s[i]:
        break
    elif i == len(s)-1:
        flag = 2

if flag == 1:
    print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2))))
elif flag == 2:
    print((k*len(s))//2)
else:
    print(k*ans) s = input() s input() input k = int(input()) k int(input()) int input() input ans = 0 ans 0 soui = 0 soui 0 moji = s[0] moji s[0] s 0 for i in range(1,len(s)):
    if s[i] == s[i-1] and soui == 0:
        ans += 1
        soui = 1
    elif soui == 1:
        soui = 0 i range(1,len(s)) range 1 len(s) len s if s[i] == s[i-1] and soui == 0:
        ans += 1
        soui = 1
    elif soui == 1:
        soui = 0 s[i] == s[i-1] and soui == 0 s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 soui == 0 soui 0 ans += 1 ans 1 soui = 1 soui 1 elif soui == 1:
        soui = 0 soui == 1 soui 1 soui = 0 soui 0 flag = 0 flag 0 a = 0 a 0 b = 0 b 0 while s[0] == s[a] and a != len(s)-1:
    a += 1 s[0] == s[a] and a != len(s)-1 s[0] == s[a] s[0] s 0 s[a] s a a != len(s)-1 a len(s)-1 len(s) len s 1 a += 1 a 1 while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1:
    b += 1 s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1 s[len(s)-1-b] == s[len(s)-1] s[len(s)-1-b] s len(s)-1-b len(s)-1 len(s) len s 1 b s[len(s)-1] s len(s)-1 len(s) len s 1 b != len(s)-1 b len(s)-1 len(s) len s 1 b += 1 b 1 if s[0] == s[len(s)-1]:
    flag = 1 s[0] == s[len(s)-1] s[0] s 0 s[len(s)-1] s len(s)-1 len(s) len s 1 flag = 1 flag 1 for i in range(len(s)):
    if moji != s[i]:
        break
    elif i == len(s)-1:
        flag = 2 i range(len(s)) range len(s) len s if moji != s[i]:
        break
    elif i == len(s)-1:
        flag = 2 moji != s[i] moji s[i] s i break elif i == len(s)-1:
        flag = 2 i == len(s)-1 i len(s)-1 len(s) len s 1 flag = 2 flag 2 if flag == 1:
    print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2))))
elif flag == 2:
    print((k*len(s))//2)
else:
    print(k*ans) flag == 1 flag 1 print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2)))) print (k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2))) k*ans k ans (k-1)*((a//2)+(b//2)-((a+b)//2)) k-1 k 1 (a//2)+(b//2)-((a+b)//2) (a//2)+(b//2) a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 elif flag == 2:
    print((k*len(s))//2) flag == 2 flag 2 print((k*len(s))//2) print (k*len(s))//2 k*len(s) k len(s) len s 2 print(k*ans) print k*ans k ans a = 0 0 a soui = 1 1 soui ans += 1 1 ans b = 0 0 b moji = s[0] s[0] moji a += 1 1 a flag = 2 2 flag soui = 0 0 soui flag = 1 1 flag k = int(input()) int(input()) k ans = 0 0 ans s = input() input() s flag = 0 0 flag soui = 0 0 soui b += 1 1 b
s = input()
k = int(input())
ans = 0
soui = 0
moji = s[0]

for i in range(1,len(s)):
    if s[i] == s[i-1] and soui == 0:
        ans += 1
        soui = 1
    elif soui == 1:
        soui = 0


flag = 0
a = 0
b = 0

while s[0] == s[a] and a != len(s)-1:
    a += 1

while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1:
    b += 1


if s[0] == s[len(s)-1]:
    flag = 1

for i in range(len(s)):
    if moji != s[i]:
        break
    elif i == len(s)-1:
        flag = 2

if flag == 1:
    print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2))))
elif flag == 2:
    print((k*len(s))//2)
else:
    print(k*ans)
