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

if list(s[0]*len(s))==s:
	#print('a')
	print(len(s)*k//2)
	exit()

res = [1]
for i in range(len(s)-1):
	if s[i]==s[i+1]:
		res[-1] += 1
	else:
		res.append(1)
ans = 0
for i in res:
	ans += (i//2)*k
if s[0]==s[-1]:
	diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2)
	ans += diff*(k-1)
print(ans) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input if list(s[0]*len(s))==s:
	#print('a')
	print(len(s)*k//2)
	exit() list(s[0]*len(s))==s list(s[0]*len(s)) list s[0]*len(s) s[0] s 0 len(s) len s s print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 exit() exit res = [1] res [1] 1 for i in range(len(s)-1):
	if s[i]==s[i+1]:
		res[-1] += 1
	else:
		res.append(1) i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]==s[i+1]:
		res[-1] += 1
	else:
		res.append(1) s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 res[-1] += 1 res[-1] res -1 1 res.append(1) res.append res append 1 ans = 0 ans 0 for i in res:
	ans += (i//2)*k i res ans += (i//2)*k ans (i//2)*k i//2 i 2 k if s[0]==s[-1]:
	diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2)
	ans += diff*(k-1) s[0]==s[-1] s[0] s 0 s[-1] s -1 diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2) diff (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2) (res[0]+res[-1])//2 res[0]+res[-1] res[0] res 0 res[-1] res -1 2 res[0]//2 + res[-1]//2 res[0]//2 res[0] res 0 2 res[-1]//2 res[-1] res -1 2 ans += diff*(k-1) ans diff*(k-1) diff k-1 k 1 print(ans) print ans ans += diff*(k-1) diff*(k-1) ans k = int(input()) int(input()) k s = list(input()) list(input()) s diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2) (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2) diff res = [1] [1] res ans += (i//2)*k (i//2)*k ans ans = 0 0 ans
s = list(input())
k = int(input())

if list(s[0]*len(s))==s:
	#print('a')
	print(len(s)*k//2)
	exit()

res = [1]
for i in range(len(s)-1):
	if s[i]==s[i+1]:
		res[-1] += 1
	else:
		res.append(1)
ans = 0
for i in res:
	ans += (i//2)*k
if s[0]==s[-1]:
	diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2)
	ans += diff*(k-1)
print(ans)
