#!/usr/bin/env python3
from itertools import*
s = input()
k = int(input())
t = [len(list(e)) for _, e in groupby(s)]
if len(set(s)) == 1:
    a = len(s) * k // 2
elif k > 1 and s[0] == s[-1]:
    p = sum(e // 2 for e in t[1:-1]) * k
    l, r = t[0], t[-1]
    q = (l + r) // 2 * ~-k + l // 2 + r // 2
    a = p + q
else:
    a = sum(e // 2 for e in t) * k
print(a) from itertools import* s = input() s input() input k = int(input()) k int(input()) int input() input len(list(e)) for _, e in groupby(s) for _, e in groupby(s) _ e groupby(s) groupby s for _, e in groupby(s) len(list(e)) len list(e) list e t = [len(list(e)) for _, e in groupby(s)] t [len(list(e)) for _, e in groupby(s)] if len(set(s)) == 1:
    a = len(s) * k // 2
elif k > 1 and s[0] == s[-1]:
    p = sum(e // 2 for e in t[1:-1]) * k
    l, r = t[0], t[-1]
    q = (l + r) // 2 * ~-k + l // 2 + r // 2
    a = p + q
else:
    a = sum(e // 2 for e in t) * k len(set(s)) == 1 len(set(s)) len set(s) set s 1 a = len(s) * k // 2 a len(s) * k // 2 len(s) * k len(s) len s k 2 elif k > 1 and s[0] == s[-1]:
    p = sum(e // 2 for e in t[1:-1]) * k
    l, r = t[0], t[-1]
    q = (l + r) // 2 * ~-k + l // 2 + r // 2
    a = p + q k > 1 and s[0] == s[-1] k > 1 k 1 s[0] == s[-1] s[0] s 0 s[-1] s -1 p = sum(e // 2 for e in t[1:-1]) * k p sum(e // 2 for e in t[1:-1]) * k sum(e // 2 for e in t[1:-1]) sum e // 2 e 2 k l, r = t[0], t[-1] l t[0] t 0 r t[-1] t -1 q = (l + r) // 2 * ~-k + l // 2 + r // 2 q (l + r) // 2 * ~-k + l // 2 + r // 2 (l + r) // 2 * ~-k + l // 2 (l + r) // 2 * ~-k (l + r) // 2 l + r l r 2 ~-k -k k l // 2 l 2 r // 2 r 2 a = p + q a p + q p q a = sum(e // 2 for e in t) * k a sum(e // 2 for e in t) * k sum(e // 2 for e in t) sum e // 2 e 2 k print(a) print a t = [len(list(e)) for _, e in groupby(s)] [len(list(e)) for _, e in groupby(s)] t q = (l + r) // 2 * ~-k + l // 2 + r // 2 (l + r) // 2 * ~-k + l // 2 + r // 2 q a = len(s) * k // 2 len(s) * k // 2 a k = int(input()) int(input()) k a = sum(e // 2 for e in t) * k sum(e // 2 for e in t) * k a p = sum(e // 2 for e in t[1:-1]) * k sum(e // 2 for e in t[1:-1]) * k p s = input() input() s l, r = t[0], t[-1] t[0] l r = t[0], t[-1] t[-1] r a = p + q p + q a
#!/usr/bin/env python3
from itertools import*
s = input()
k = int(input())
t = [len(list(e)) for _, e in groupby(s)]
if len(set(s)) == 1:
    a = len(s) * k // 2
elif k > 1 and s[0] == s[-1]:
    p = sum(e // 2 for e in t[1:-1]) * k
    l, r = t[0], t[-1]
    q = (l + r) // 2 * ~-k + l // 2 + r // 2
    a = p + q
else:
    a = sum(e // 2 for e in t) * k
print(a)