from itertools import groupby
s = input()
k = int(input())
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()
g = [len(list(v)) for _, v in groupby(s)]
ans = sum(i//2 for i in g)*k
if s[0] != s[-1]:
    print(ans)
    exit()
a, *_, b = g
ans -= (a//2 + b//2 - (a+b)//2)*(k-1)
print(ans) from itertools import groupby s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print(len(s)*k//2)
    exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 exit() exit len(list(v)) for _, v in groupby(s) for _, v in groupby(s) _ v groupby(s) groupby s for _, v in groupby(s) len(list(v)) len list(v) list v g = [len(list(v)) for _, v in groupby(s)] g [len(list(v)) for _, v in groupby(s)] ans = sum(i//2 for i in g)*k ans sum(i//2 for i in g)*k sum(i//2 for i in g) sum i//2 i 2 k if s[0] != s[-1]:
    print(ans)
    exit() s[0] != s[-1] s[0] s 0 s[-1] s -1 print(ans) print ans exit() exit a, *_, b = g a g b *_ _ ans -= (a//2 + b//2 - (a+b)//2)*(k-1) ans (a//2 + b//2 - (a+b)//2)*(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 k-1 k 1 print(ans) print ans g = [len(list(v)) for _, v in groupby(s)] [len(list(v)) for _, v in groupby(s)] g s = input() input() s ans = sum(i//2 for i in g)*k sum(i//2 for i in g)*k ans k = int(input()) int(input()) k ans -= (a//2 + b//2 - (a+b)//2)*(k-1) (a//2 + b//2 - (a+b)//2)*(k-1) ans a, *_, b = g g a b = g g b
from itertools import groupby
s = input()
k = int(input())
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()
g = [len(list(v)) for _, v in groupby(s)]
ans = sum(i//2 for i in g)*k
if s[0] != s[-1]:
    print(ans)
    exit()
a, *_, b = g
ans -= (a//2 + b//2 - (a+b)//2)*(k-1)
print(ans)
