from itertools import groupby
s = input()
k = int(input())
ans = 0
count = []
for i, j in groupby(s):
    count.append(len(list(j)))
if len(set(s)) == 1:
    ans = (len(s)*k)//2
elif k > 1 and s[0] == s[-1]:
    f = count[0]
    e = count[-1]
    ans += f//2 + e//2 + (f+e)//2*(k-1)
    for n in count[1:-1]:
        ans += n//2 * k
else:
    for n in count:
        ans += n//2 * k
print(ans) from itertools import groupby s = input() s input() input k = int(input()) k int(input()) int input() input ans = 0 ans 0 count = [] count [] for i, j in groupby(s):
    count.append(len(list(j))) i j groupby(s) groupby s count.append(len(list(j))) count.append count append len(list(j)) len list(j) list j if len(set(s)) == 1:
    ans = (len(s)*k)//2
elif k > 1 and s[0] == s[-1]:
    f = count[0]
    e = count[-1]
    ans += f//2 + e//2 + (f+e)//2*(k-1)
    for n in count[1:-1]:
        ans += n//2 * k
else:
    for n in count:
        ans += n//2 * k len(set(s)) == 1 len(set(s)) len set(s) set s 1 ans = (len(s)*k)//2 ans (len(s)*k)//2 len(s)*k len(s) len s k 2 elif k > 1 and s[0] == s[-1]:
    f = count[0]
    e = count[-1]
    ans += f//2 + e//2 + (f+e)//2*(k-1)
    for n in count[1:-1]:
        ans += n//2 * k k > 1 and s[0] == s[-1] k > 1 k 1 s[0] == s[-1] s[0] s 0 s[-1] s -1 f = count[0] f count[0] count 0 e = count[-1] e count[-1] count -1 ans += f//2 + e//2 + (f+e)//2*(k-1) ans f//2 + e//2 + (f+e)//2*(k-1) f//2 + e//2 f//2 f 2 e//2 e 2 (f+e)//2*(k-1) (f+e)//2 f+e f e 2 k-1 k 1 for n in count[1:-1]:
        ans += n//2 * k n count[1:-1] count 1:-1 1 -1 ans += n//2 * k ans n//2 * k n//2 n 2 k for n in count:
        ans += n//2 * k n count ans += n//2 * k ans n//2 * k n//2 n 2 k print(ans) print ans count = [] [] count ans += n//2 * k n//2 * k ans f = count[0] count[0] f k = int(input()) int(input()) k s = input() input() s ans += f//2 + e//2 + (f+e)//2*(k-1) f//2 + e//2 + (f+e)//2*(k-1) ans ans = (len(s)*k)//2 (len(s)*k)//2 ans ans = 0 0 ans e = count[-1] count[-1] e ans += n//2 * k n//2 * k ans
from itertools import groupby
s = input()
k = int(input())
ans = 0
count = []
for i, j in groupby(s):
    count.append(len(list(j)))
if len(set(s)) == 1:
    ans = (len(s)*k)//2
elif k > 1 and s[0] == s[-1]:
    f = count[0]
    e = count[-1]
    ans += f//2 + e//2 + (f+e)//2*(k-1)
    for n in count[1:-1]:
        ans += n//2 * k
else:
    for n in count:
        ans += n//2 * k
print(ans)
