s = list(input())
k = int(input())
x = []
ans = 0
cnt = 1
for i in range(len(s)):
    if i < len(s) - 1 and s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        x.append(cnt)
        cnt = 1
cnt = 0
if s[0] == s[len(s) - 1]:
    cnt = x[0] // 2 + x[-1] // 2 - (x[0] + x[-1]) // 2

print(ans * k - cnt * (k - 1) if len(set(s)) != 1 else len(s) * k // 2) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input x = [] x [] ans = 0 ans 0 cnt = 1 cnt 1 for i in range(len(s)):
    if i < len(s) - 1 and s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        x.append(cnt)
        cnt = 1 i range(len(s)) range len(s) len s if i < len(s) - 1 and s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        x.append(cnt)
        cnt = 1 i < len(s) - 1 and s[i] == s[i + 1] i < len(s) - 1 i len(s) - 1 len(s) len s 1 s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 cnt += 1 cnt 1 ans += cnt // 2 ans cnt // 2 cnt 2 x.append(cnt) x.append x append cnt cnt = 1 cnt 1 cnt = 0 cnt 0 if s[0] == s[len(s) - 1]:
    cnt = x[0] // 2 + x[-1] // 2 - (x[0] + x[-1]) // 2 s[0] == s[len(s) - 1] s[0] s 0 s[len(s) - 1] s len(s) - 1 len(s) len s 1 cnt = x[0] // 2 + x[-1] // 2 - (x[0] + x[-1]) // 2 cnt x[0] // 2 + x[-1] // 2 - (x[0] + x[-1]) // 2 x[0] // 2 + x[-1] // 2 x[0] // 2 x[0] x 0 2 x[-1] // 2 x[-1] x -1 2 (x[0] + x[-1]) // 2 x[0] + x[-1] x[0] x 0 x[-1] x -1 2 print(ans * k - cnt * (k - 1) if len(set(s)) != 1 else len(s) * k // 2) print ans * k - cnt * (k - 1) if len(set(s)) != 1 else len(s) * k // 2 len(set(s)) != 1 len(set(s)) len set(s) set s 1 ans * k - cnt * (k - 1) ans * k ans k cnt * (k - 1) cnt k - 1 k 1 len(s) * k // 2 len(s) * k len(s) len s k 2 ans = 0 0 ans k = int(input()) int(input()) k s = list(input()) list(input()) s ans += cnt // 2 cnt // 2 ans cnt += 1 1 cnt cnt = 1 1 cnt cnt = x[0] // 2 + x[-1] // 2 - (x[0] + x[-1]) // 2 x[0] // 2 + x[-1] // 2 - (x[0] + x[-1]) // 2 cnt x = [] [] x cnt = 1 1 cnt cnt = 0 0 cnt
s = list(input())
k = int(input())
x = []
ans = 0
cnt = 1
for i in range(len(s)):
    if i < len(s) - 1 and s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        x.append(cnt)
        cnt = 1
cnt = 0
if s[0] == s[len(s) - 1]:
    cnt = x[0] // 2 + x[-1] // 2 - (x[0] + x[-1]) // 2

print(ans * k - cnt * (k - 1) if len(set(s)) != 1 else len(s) * k // 2)