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

ans = 0
lens = len(s)
# n -> n//2

def tansaku(moji, n, m, k):
	# n以上 m未満を探索する.
	ansr = 0
	cntt = 1
	for i in range(n, m-1):
		if moji[i] == moji[i + 1]:
			cntt += 1
		else:
			ansr += (cntt // 2) * k
			cntt = 1
	ansr += (cntt // 2) * k
	return ansr

cnnt = 1
hentai = False
for i in range(lens-1):
	if s[i] == s[i+1]:
		cnnt += 1
if cnnt == lens:
	hentai = True

if not hentai:
	if k >= 2:
		zencnts = 0
		atocnts = 0
		if s[lens-1] == s[0]:
			for i in range(lens):
				if s[lens-1-i] == s[lens-1]:
					zencnts += 1
				else:
					break
			for i in range(lens):
				if s[i] == s[0]:
					atocnts += 1
				else:
					break
		news = s[atocnts:] + s[:atocnts]
		news1 = s[atocnts:]
		news2 = s[:atocnts]
		ans += tansaku(news, 0, lens, k-1)
		ans += tansaku(news1, 0, lens-atocnts, 1)
		ans += tansaku(news2, 0, atocnts, 1)
		print(ans)
	else:
		ans += tansaku(s, 0, lens, 1)
		print(ans)
else:
	print((lens*k)//2) s = input() s input() input k = int(input()) k int(input()) int input() input ans = 0 ans 0 lens = len(s) lens len(s) len s def tansaku(moji, n, m, k):
	# n以上 m未満を探索する.
	ansr = 0
	cntt = 1
	for i in range(n, m-1):
		if moji[i] == moji[i + 1]:
			cntt += 1
		else:
			ansr += (cntt // 2) * k
			cntt = 1
	ansr += (cntt // 2) * k
	return ansr tansaku ansr = 0 ansr 0 cntt = 1 cntt 1 for i in range(n, m-1):
		if moji[i] == moji[i + 1]:
			cntt += 1
		else:
			ansr += (cntt // 2) * k
			cntt = 1
	 i range(n, m-1) range n m-1 m 1 if moji[i] == moji[i + 1]:
			cntt += 1
		else:
			ansr += (cntt // 2) * k
			cntt = 1
	 moji[i] == moji[i + 1] moji[i] moji i moji[i + 1] moji i + 1 i 1 cntt += 1 cntt 1 ansr += (cntt // 2) * k ansr (cntt // 2) * k cntt // 2 cntt 2 k cntt = 1 cntt 1 ansr += (cntt // 2) * k ansr (cntt // 2) * k cntt // 2 cntt 2 k return ansr ansr moji moji n n m m k k cnnt = 1 cnnt 1 hentai = False hentai False for i in range(lens-1):
	if s[i] == s[i+1]:
		cnnt += 1 i range(lens-1) range lens-1 lens 1 if s[i] == s[i+1]:
		cnnt += 1 s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 cnnt += 1 cnnt 1 if cnnt == lens:
	hentai = True cnnt == lens cnnt lens hentai = True hentai True if not hentai:
	if k >= 2:
		zencnts = 0
		atocnts = 0
		if s[lens-1] == s[0]:
			for i in range(lens):
				if s[lens-1-i] == s[lens-1]:
					zencnts += 1
				else:
					break
			for i in range(lens):
				if s[i] == s[0]:
					atocnts += 1
				else:
					break
		news = s[atocnts:] + s[:atocnts]
		news1 = s[atocnts:]
		news2 = s[:atocnts]
		ans += tansaku(news, 0, lens, k-1)
		ans += tansaku(news1, 0, lens-atocnts, 1)
		ans += tansaku(news2, 0, atocnts, 1)
		print(ans)
	else:
		ans += tansaku(s, 0, lens, 1)
		print(ans)
else:
	print((lens*k)//2) not hentai hentai if k >= 2:
		zencnts = 0
		atocnts = 0
		if s[lens-1] == s[0]:
			for i in range(lens):
				if s[lens-1-i] == s[lens-1]:
					zencnts += 1
				else:
					break
			for i in range(lens):
				if s[i] == s[0]:
					atocnts += 1
				else:
					break
		news = s[atocnts:] + s[:atocnts]
		news1 = s[atocnts:]
		news2 = s[:atocnts]
		ans += tansaku(news, 0, lens, k-1)
		ans += tansaku(news1, 0, lens-atocnts, 1)
		ans += tansaku(news2, 0, atocnts, 1)
		print(ans)
	else:
		ans += tansaku(s, 0, lens, 1)
		print(ans) k >= 2 k 2 zencnts = 0 zencnts 0 atocnts = 0 atocnts 0 if s[lens-1] == s[0]:
			for i in range(lens):
				if s[lens-1-i] == s[lens-1]:
					zencnts += 1
				else:
					break
			for i in range(lens):
				if s[i] == s[0]:
					atocnts += 1
				else:
					break
		 s[lens-1] == s[0] s[lens-1] s lens-1 lens 1 s[0] s 0 for i in range(lens):
				if s[lens-1-i] == s[lens-1]:
					zencnts += 1
				else:
					break
			 i range(lens) range lens if s[lens-1-i] == s[lens-1]:
					zencnts += 1
				else:
					break
			 s[lens-1-i] == s[lens-1] s[lens-1-i] s lens-1-i lens-1 lens 1 i s[lens-1] s lens-1 lens 1 zencnts += 1 zencnts 1 break for i in range(lens):
				if s[i] == s[0]:
					atocnts += 1
				else:
					break
		 i range(lens) range lens if s[i] == s[0]:
					atocnts += 1
				else:
					break
		 s[i] == s[0] s[i] s i s[0] s 0 atocnts += 1 atocnts 1 break news = s[atocnts:] + s[:atocnts] news s[atocnts:] + s[:atocnts] s[atocnts:] s atocnts: atocnts s[:atocnts] s :atocnts atocnts news1 = s[atocnts:] news1 s[atocnts:] s atocnts: atocnts news2 = s[:atocnts] news2 s[:atocnts] s :atocnts atocnts ans += tansaku(news, 0, lens, k-1) ans tansaku(news, 0, lens, k-1) tansaku news 0 lens k-1 k 1 ans += tansaku(news1, 0, lens-atocnts, 1) ans tansaku(news1, 0, lens-atocnts, 1) tansaku news1 0 lens-atocnts lens atocnts 1 ans += tansaku(news2, 0, atocnts, 1) ans tansaku(news2, 0, atocnts, 1) tansaku news2 0 atocnts 1 print(ans) print ans ans += tansaku(s, 0, lens, 1) ans tansaku(s, 0, lens, 1) tansaku s 0 lens 1 print(ans) print ans print((lens*k)//2) print (lens*k)//2 lens*k lens k 2 atocnts += 1 1 atocnts cnnt = 1 1 cnnt ans += tansaku(s, 0, lens, 1) tansaku(s, 0, lens, 1) ans hentai = True True hentai atocnts = 0 0 atocnts ans = 0 0 ans news1 = s[atocnts:] s[atocnts:] news1 s = input() input() s ans += tansaku(news1, 0, lens-atocnts, 1) tansaku(news1, 0, lens-atocnts, 1) ans news = s[atocnts:] + s[:atocnts] s[atocnts:] + s[:atocnts] news lens = len(s) len(s) lens cnnt += 1 1 cnnt ans += tansaku(news, 0, lens, k-1) tansaku(news, 0, lens, k-1) ans zencnts = 0 0 zencnts def tansaku(moji, n, m, k):
	# n以上 m未満を探索する.
	ansr = 0
	cntt = 1
	for i in range(n, m-1):
		if moji[i] == moji[i + 1]:
			cntt += 1
		else:
			ansr += (cntt // 2) * k
			cntt = 1
	ansr += (cntt // 2) * k
	return ansr def tansaku(moji, n, m, k):
	# n以上 m未満を探索する.
	ansr = 0
	cntt = 1
	for i in range(n, m-1):
		if moji[i] == moji[i + 1]:
			cntt += 1
		else:
			ansr += (cntt // 2) * k
			cntt = 1
	ansr += (cntt // 2) * k
	return ansr tansaku ans += tansaku(news2, 0, atocnts, 1) tansaku(news2, 0, atocnts, 1) ans hentai = False False hentai k = int(input()) int(input()) k news2 = s[:atocnts] s[:atocnts] news2 zencnts += 1 1 zencnts
s = input()
k = int(input())

ans = 0
lens = len(s)
# n -> n//2

def tansaku(moji, n, m, k):
	# n以上 m未満を探索する.
	ansr = 0
	cntt = 1
	for i in range(n, m-1):
		if moji[i] == moji[i + 1]:
			cntt += 1
		else:
			ansr += (cntt // 2) * k
			cntt = 1
	ansr += (cntt // 2) * k
	return ansr

cnnt = 1
hentai = False
for i in range(lens-1):
	if s[i] == s[i+1]:
		cnnt += 1
if cnnt == lens:
	hentai = True

if not hentai:
	if k >= 2:
		zencnts = 0
		atocnts = 0
		if s[lens-1] == s[0]:
			for i in range(lens):
				if s[lens-1-i] == s[lens-1]:
					zencnts += 1
				else:
					break
			for i in range(lens):
				if s[i] == s[0]:
					atocnts += 1
				else:
					break
		news = s[atocnts:] + s[:atocnts]
		news1 = s[atocnts:]
		news2 = s[:atocnts]
		ans += tansaku(news, 0, lens, k-1)
		ans += tansaku(news1, 0, lens-atocnts, 1)
		ans += tansaku(news2, 0, atocnts, 1)
		print(ans)
	else:
		ans += tansaku(s, 0, lens, 1)
		print(ans)
else:
	print((lens*k)//2)