s = input()
k = int(input())
cnt = 0
if len(set(list(s))) == 1:
	cnt = k * len(s) // 2
	print(cnt)
	exit()

x, y = 0, 0
t = s + s
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		x += 1
		s = s[:i+1] + '#' + s[i+2:]

for i in range(len(t) - 1):
	if t[i] == t[i + 1]:
		y += 1
		t = t[:i+1] + '#' + t[i+2:]

cnt = x + (k - 1) * (y - x)
print(cnt) s = input() s input() input k = int(input()) k int(input()) int input() input cnt = 0 cnt 0 if len(set(list(s))) == 1:
	cnt = k * len(s) // 2
	print(cnt)
	exit() len(set(list(s))) == 1 len(set(list(s))) len set(list(s)) set list(s) list s 1 cnt = k * len(s) // 2 cnt k * len(s) // 2 k * len(s) k len(s) len s 2 print(cnt) print cnt exit() exit x, y = 0, 0 x 0 y 0 t = s + s t s + s s s for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		x += 1
		s = s[:i+1] + '#' + s[i+2:] i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if s[i] == s[i + 1]:
		x += 1
		s = s[:i+1] + '#' + s[i+2:] s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 x += 1 x 1 s = s[:i+1] + '#' + s[i+2:] s s[:i+1] + '#' + s[i+2:] s[:i+1] + '#' s[:i+1] s :i+1 i+1 i 1 '#' s[i+2:] s i+2: i+2 i 2 for i in range(len(t) - 1):
	if t[i] == t[i + 1]:
		y += 1
		t = t[:i+1] + '#' + t[i+2:] i range(len(t) - 1) range len(t) - 1 len(t) len t 1 if t[i] == t[i + 1]:
		y += 1
		t = t[:i+1] + '#' + t[i+2:] t[i] == t[i + 1] t[i] t i t[i + 1] t i + 1 i 1 y += 1 y 1 t = t[:i+1] + '#' + t[i+2:] t t[:i+1] + '#' + t[i+2:] t[:i+1] + '#' t[:i+1] t :i+1 i+1 i 1 '#' t[i+2:] t i+2: i+2 i 2 cnt = x + (k - 1) * (y - x) cnt x + (k - 1) * (y - x) x (k - 1) * (y - x) k - 1 k 1 y - x y x print(cnt) print cnt k = int(input()) int(input()) k cnt = k * len(s) // 2 k * len(s) // 2 cnt t = s + s s + s t x += 1 1 x cnt = x + (k - 1) * (y - x) x + (k - 1) * (y - x) cnt t = t[:i+1] + '#' + t[i+2:] t[:i+1] + '#' + t[i+2:] t s = s[:i+1] + '#' + s[i+2:] s[:i+1] + '#' + s[i+2:] s y = 0, 0 0 y s = input() input() s y += 1 1 y cnt = 0 0 cnt x, y = 0, 0 0 x
s = input()
k = int(input())
cnt = 0
if len(set(list(s))) == 1:
	cnt = k * len(s) // 2
	print(cnt)
	exit()

x, y = 0, 0
t = s + s
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		x += 1
		s = s[:i+1] + '#' + s[i+2:]

for i in range(len(t) - 1):
	if t[i] == t[i + 1]:
		y += 1
		t = t[:i+1] + '#' + t[i+2:]

cnt = x + (k - 1) * (y - x)
print(cnt)