S = gets.chomp
K = gets.to_i

count = 0
count_base = 0

ss = S.split("")

if ss.uniq.size == 1 then
	count = ss.size * K / 2
else
	temp = nil
	temp_count = 0

	(0...ss.size).each{ |i|
		if temp == ss[i] then
			temp_count += 1
		else
			count_base += temp_count / 2
			temp_count = 1
		end
		temp = ss[i]
	}

	flag = false

	if temp_count != 0 then
		if temp == ss[0] && (ss.size == 1 || temp != ss[1]) && (temp_count % 2 == 1) then
			temp_count += 1
			flag = true
		end
		count_base += temp_count / 2
	end

	count = count_base * K
	
	count -= 1 if flag
end

puts count