from itertools import groupby

s = input()
k = int(input())
r = len(s) * k // 2
a = [len(tuple(g)) & 1 for _, g in groupby(s)]
if len(a) > 1:
  r -= sum(a) * k // 2
  if s[0] == s[-1] and a[0] & a[-1]:
    r += k - 1
print(r) from itertools import groupby s = input() s input() input k = int(input()) k int(input()) int input() input r = len(s) * k // 2 r len(s) * k // 2 len(s) * k len(s) len s k 2 len(tuple(g)) & 1 for _, g in groupby(s) for _, g in groupby(s) _ g groupby(s) groupby s for _, g in groupby(s) len(tuple(g)) & 1 len(tuple(g)) len tuple(g) tuple g 1 a = [len(tuple(g)) & 1 for _, g in groupby(s)] a [len(tuple(g)) & 1 for _, g in groupby(s)] if len(a) > 1:
  r -= sum(a) * k // 2
  if s[0] == s[-1] and a[0] & a[-1]:
    r += k - 1 len(a) > 1 len(a) len a 1 r -= sum(a) * k // 2 r sum(a) * k // 2 sum(a) * k sum(a) sum a k 2 if s[0] == s[-1] and a[0] & a[-1]:
    r += k - 1 s[0] == s[-1] and a[0] & a[-1] s[0] == s[-1] s[0] s 0 s[-1] s -1 a[0] & a[-1] a[0] a 0 a[-1] a -1 r += k - 1 r k - 1 k 1 print(r) print r a = [len(tuple(g)) & 1 for _, g in groupby(s)] [len(tuple(g)) & 1 for _, g in groupby(s)] a r = len(s) * k // 2 len(s) * k // 2 r r -= sum(a) * k // 2 sum(a) * k // 2 r s = input() input() s r += k - 1 k - 1 r k = int(input()) int(input()) k
from itertools import groupby

s = input()
k = int(input())
r = len(s) * k // 2
a = [len(tuple(g)) & 1 for _, g in groupby(s)]
if len(a) > 1:
  r -= sum(a) * k // 2
  if s[0] == s[-1] and a[0] & a[-1]:
    r += k - 1
print(r)
