S = input()
K = int(input())

curr = S[0]
tmp = ""
T = []
for s in S:
    if s == curr:
        tmp += s
    else:
        T.append(tmp)
        curr = s
        tmp = s
T.append(tmp)

if len(T) == 1:
    res = (len(S) * K) // 2
    print(res)
    exit(0)

res = 0
t_first = T[0]
t_last = T[-1]

if t_first[0] != t_last[0]:
    res += (len(t_first) // 2) * K
    res += (len(t_last) // 2) * K
else:
    res += len(t_first) // 2
    res += len(t_last) // 2
    res += (len(t_first + t_last) // 2) * (K - 1)

for t in T[1:-1]:
    res += (len(t) // 2) * K

print(res) S = input() S input() input K = int(input()) K int(input()) int input() input curr = S[0] curr S[0] S 0 tmp = "" tmp "" T = [] T [] for s in S:
    if s == curr:
        tmp += s
    else:
        T.append(tmp)
        curr = s
        tmp = s s S if s == curr:
        tmp += s
    else:
        T.append(tmp)
        curr = s
        tmp = s s == curr s curr tmp += s tmp s T.append(tmp) T.append T append tmp curr = s curr s tmp = s tmp s T.append(tmp) T.append T append tmp if len(T) == 1:
    res = (len(S) * K) // 2
    print(res)
    exit(0) len(T) == 1 len(T) len T 1 res = (len(S) * K) // 2 res (len(S) * K) // 2 len(S) * K len(S) len S K 2 print(res) print res exit(0) exit 0 res = 0 res 0 t_first = T[0] t_first T[0] T 0 t_last = T[-1] t_last T[-1] T -1 if t_first[0] != t_last[0]:
    res += (len(t_first) // 2) * K
    res += (len(t_last) // 2) * K
else:
    res += len(t_first) // 2
    res += len(t_last) // 2
    res += (len(t_first + t_last) // 2) * (K - 1) t_first[0] != t_last[0] t_first[0] t_first 0 t_last[0] t_last 0 res += (len(t_first) // 2) * K res (len(t_first) // 2) * K len(t_first) // 2 len(t_first) len t_first 2 K res += (len(t_last) // 2) * K res (len(t_last) // 2) * K len(t_last) // 2 len(t_last) len t_last 2 K res += len(t_first) // 2 res len(t_first) // 2 len(t_first) len t_first 2 res += len(t_last) // 2 res len(t_last) // 2 len(t_last) len t_last 2 res += (len(t_first + t_last) // 2) * (K - 1) res (len(t_first + t_last) // 2) * (K - 1) len(t_first + t_last) // 2 len(t_first + t_last) len t_first + t_last t_first t_last 2 K - 1 K 1 for t in T[1:-1]:
    res += (len(t) // 2) * K t T[1:-1] T 1:-1 1 -1 res += (len(t) // 2) * K res (len(t) // 2) * K len(t) // 2 len(t) len t 2 K print(res) print res tmp = "" "" tmp res = (len(S) * K) // 2 (len(S) * K) // 2 res tmp += s s tmp res = 0 0 res res += (len(t) // 2) * K (len(t) // 2) * K res res += (len(t_first + t_last) // 2) * (K - 1) (len(t_first + t_last) // 2) * (K - 1) res res += (len(t_last) // 2) * K (len(t_last) // 2) * K res K = int(input()) int(input()) K res += (len(t_first) // 2) * K (len(t_first) // 2) * K res S = input() input() S res += len(t_last) // 2 len(t_last) // 2 res T = [] [] T t_first = T[0] T[0] t_first curr = S[0] S[0] curr tmp = s s tmp t_last = T[-1] T[-1] t_last res += len(t_first) // 2 len(t_first) // 2 res curr = s s curr
S = input()
K = int(input())

curr = S[0]
tmp = ""
T = []
for s in S:
    if s == curr:
        tmp += s
    else:
        T.append(tmp)
        curr = s
        tmp = s
T.append(tmp)

if len(T) == 1:
    res = (len(S) * K) // 2
    print(res)
    exit(0)

res = 0
t_first = T[0]
t_last = T[-1]

if t_first[0] != t_last[0]:
    res += (len(t_first) // 2) * K
    res += (len(t_last) // 2) * K
else:
    res += len(t_first) // 2
    res += len(t_last) // 2
    res += (len(t_first + t_last) // 2) * (K - 1)

for t in T[1:-1]:
    res += (len(t) // 2) * K

print(res)
