# A - Connection and Disconnection
def count(s, c):
	count_ = s.count(c*2)
	
	while c*3 in s:
		s = s.replace(c*3, c+'_'+c)
	
	while c*2 in s:
		s = s.replace(c*2, c+'_')
	
	return min(count_, s.count('_'))


def get_startswith(s, c):
	key = c
	
	while s.startswith(key+c):
		key += c
	
	return len(key)
	
	
def get_endswith(s, c):
	key = c
	
	while s.endswith(key+c):
		key += c
	
	return len(key)


import string

S = input()
K = int(input())

lower = string.ascii_lowercase
ans = 0

if S[0] == S[-1:]:
	start = get_startswith(S, S[0])
	end = get_endswith(S, S[0])	
	
	if start == end == len(S):
		print(len(S) * K // 2)
	else:
		ans = 0
		
		ans += start // 2
		ans += end // 2
		ans += ((start + end) // 2) * (K - 1)
		
		for c in lower:
			ans += count(S[start:len(S)-end], c) * K

		print(ans)	
else:
	for c in lower:
		ans += count(S, c)

	print(ans * K) def count(s, c):
	count_ = s.count(c*2)
	
	while c*3 in s:
		s = s.replace(c*3, c+'_'+c)
	
	while c*2 in s:
		s = s.replace(c*2, c+'_')
	
	return min(count_, s.count('_')) count count_ = s.count(c*2) count_ s.count(c*2) s.count s count c*2 c 2 while c*3 in s:
		s = s.replace(c*3, c+'_'+c)
	
	 c*3 in s c*3 c 3 s s = s.replace(c*3, c+'_'+c) s s.replace(c*3, c+'_'+c) s.replace s replace c*3 c 3 c+'_'+c c+'_' c '_' c while c*2 in s:
		s = s.replace(c*2, c+'_')
	
	 c*2 in s c*2 c 2 s s = s.replace(c*2, c+'_') s s.replace(c*2, c+'_') s.replace s replace c*2 c 2 c+'_' c '_' return min(count_, s.count('_')) min(count_, s.count('_')) min count_ s.count('_') s.count s count '_' s s c c def get_startswith(s, c):
	key = c
	
	while s.startswith(key+c):
		key += c
	
	return len(key)
	
	 get_startswith key = c key c while s.startswith(key+c):
		key += c
	
	 s.startswith(key+c) s.startswith s startswith key+c key c key += c key c return len(key) len(key) len key s s c c def get_endswith(s, c):
	key = c
	
	while s.endswith(key+c):
		key += c
	
	return len(key) get_endswith key = c key c while s.endswith(key+c):
		key += c
	
	 s.endswith(key+c) s.endswith s endswith key+c key c key += c key c return len(key) len(key) len key s s c c import string string S = input() S input() input K = int(input()) K int(input()) int input() input lower = string.ascii_lowercase lower string.ascii_lowercase string ascii_lowercase ans = 0 ans 0 if S[0] == S[-1:]:
	start = get_startswith(S, S[0])
	end = get_endswith(S, S[0])	
	
	if start == end == len(S):
		print(len(S) * K // 2)
	else:
		ans = 0
		
		ans += start // 2
		ans += end // 2
		ans += ((start + end) // 2) * (K - 1)
		
		for c in lower:
			ans += count(S[start:len(S)-end], c) * K

		print(ans)	
else:
	for c in lower:
		ans += count(S, c)

	print(ans * K) S[0] == S[-1:] S[0] S 0 S[-1:] S -1: -1 start = get_startswith(S, S[0]) start get_startswith(S, S[0]) get_startswith S S[0] S 0 end = get_endswith(S, S[0]) end get_endswith(S, S[0]) get_endswith S S[0] S 0 if start == end == len(S):
		print(len(S) * K // 2)
	else:
		ans = 0
		
		ans += start // 2
		ans += end // 2
		ans += ((start + end) // 2) * (K - 1)
		
		for c in lower:
			ans += count(S[start:len(S)-end], c) * K

		print(ans)	 start == end == len(S) start == end start end len(S) len S print(len(S) * K // 2) print len(S) * K // 2 len(S) * K len(S) len S K 2 ans = 0 ans 0 ans += start // 2 ans start // 2 start 2 ans += end // 2 ans end // 2 end 2 ans += ((start + end) // 2) * (K - 1) ans ((start + end) // 2) * (K - 1) (start + end) // 2 start + end start end 2 K - 1 K 1 for c in lower:
			ans += count(S[start:len(S)-end], c) * K

		 c lower ans += count(S[start:len(S)-end], c) * K ans count(S[start:len(S)-end], c) * K count(S[start:len(S)-end], c) count S[start:len(S)-end] S start:len(S)-end start len(S)-end len(S) len S end c K print(ans) print ans for c in lower:
		ans += count(S, c)

	 c lower ans += count(S, c) ans count(S, c) count S c print(ans * K) print ans * K ans K ans += ((start + end) // 2) * (K - 1) ((start + end) // 2) * (K - 1) ans end = get_endswith(S, S[0]) get_endswith(S, S[0]) end ans += end // 2 end // 2 ans ans += count(S[start:len(S)-end], c) * K count(S[start:len(S)-end], c) * K ans start = get_startswith(S, S[0]) get_startswith(S, S[0]) start ans = 0 0 ans lower = string.ascii_lowercase string.ascii_lowercase lower S = input() input() S def get_startswith(s, c):
	key = c
	
	while s.startswith(key+c):
		key += c
	
	return len(key)
	
	 def get_startswith(s, c):
	key = c
	
	while s.startswith(key+c):
		key += c
	
	return len(key)
	
	 get_startswith def get_endswith(s, c):
	key = c
	
	while s.endswith(key+c):
		key += c
	
	return len(key) def get_endswith(s, c):
	key = c
	
	while s.endswith(key+c):
		key += c
	
	return len(key) get_endswith ans += start // 2 start // 2 ans ans = 0 0 ans ans += count(S, c) count(S, c) ans def count(s, c):
	count_ = s.count(c*2)
	
	while c*3 in s:
		s = s.replace(c*3, c+'_'+c)
	
	while c*2 in s:
		s = s.replace(c*2, c+'_')
	
	return min(count_, s.count('_')) def count(s, c):
	count_ = s.count(c*2)
	
	while c*3 in s:
		s = s.replace(c*3, c+'_'+c)
	
	while c*2 in s:
		s = s.replace(c*2, c+'_')
	
	return min(count_, s.count('_')) count K = int(input()) int(input()) K
# A - Connection and Disconnection
def count(s, c):
	count_ = s.count(c*2)
	
	while c*3 in s:
		s = s.replace(c*3, c+'_'+c)
	
	while c*2 in s:
		s = s.replace(c*2, c+'_')
	
	return min(count_, s.count('_'))


def get_startswith(s, c):
	key = c
	
	while s.startswith(key+c):
		key += c
	
	return len(key)
	
	
def get_endswith(s, c):
	key = c
	
	while s.endswith(key+c):
		key += c
	
	return len(key)


import string

S = input()
K = int(input())

lower = string.ascii_lowercase
ans = 0

if S[0] == S[-1:]:
	start = get_startswith(S, S[0])
	end = get_endswith(S, S[0])	
	
	if start == end == len(S):
		print(len(S) * K // 2)
	else:
		ans = 0
		
		ans += start // 2
		ans += end // 2
		ans += ((start + end) // 2) * (K - 1)
		
		for c in lower:
			ans += count(S[start:len(S)-end], c) * K

		print(ans)	
else:
	for c in lower:
		ans += count(S, c)

	print(ans * K)