s = gets.chomp
k = gets.to_i

results = s + s[0]
i = 0
count = 0
while i < results.length
	if results[i] == results[i + 1] then
		results[i + 1] = "1"
		count = count + 1
		if i + 1 + 1 == results.length then
			count = count - 1
		end
	end
	i = i + 1
end
print(count * k)