from itertools import groupby

s = input()
k = int(input())

cont = [sum(1 for _ in it) for k, it in groupby(s)]

if len(cont) == 1:
    res = len(s) * k // 2
else:
    res = k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0
    for c in cont:
        if c != 1:
            res += c // 2 * k

print(res) from itertools import groupby s = input() s input() input k = int(input()) k int(input()) int input() input sum(1 for _ in it) for k, it in groupby(s) for k, it in groupby(s) k it groupby(s) groupby s for k, it in groupby(s) sum(1 for _ in it) sum 1 cont = [sum(1 for _ in it) for k, it in groupby(s)] cont [sum(1 for _ in it) for k, it in groupby(s)] if len(cont) == 1:
    res = len(s) * k // 2
else:
    res = k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0
    for c in cont:
        if c != 1:
            res += c // 2 * k len(cont) == 1 len(cont) len cont 1 res = len(s) * k // 2 res len(s) * k // 2 len(s) * k len(s) len s k 2 res = k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0 res k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0 s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 s[0] == s[-1] and cont[0] % 2 == 1 s[0] == s[-1] s[0] s 0 s[-1] s -1 cont[0] % 2 == 1 cont[0] % 2 cont[0] cont 0 2 1 cont[-1] % 2 == 1 cont[-1] % 2 cont[-1] cont -1 2 1 k-1 k 1 0 for c in cont:
        if c != 1:
            res += c // 2 * k c cont if c != 1:
            res += c // 2 * k c != 1 c 1 res += c // 2 * k res c // 2 * k c // 2 c 2 k print(res) print res res = len(s) * k // 2 len(s) * k // 2 res res = k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0 k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0 res res += c // 2 * k c // 2 * k res s = input() input() s k = int(input()) int(input()) k cont = [sum(1 for _ in it) for k, it in groupby(s)] [sum(1 for _ in it) for k, it in groupby(s)] cont
from itertools import groupby

s = input()
k = int(input())

cont = [sum(1 for _ in it) for k, it in groupby(s)]

if len(cont) == 1:
    res = len(s) * k // 2
else:
    res = k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0
    for c in cont:
        if c != 1:
            res += c // 2 * k

print(res)
