s = gets
k = gets.to_i

count = 0
left = 0
right = 0

l = s.length

if l == 0
	puts 0
elsif l == 1
	puts k / 2
else
	seclen = []
	while right < l
		while right < l && s[right] == s[right + 1]
			right += 1
		end
		section = right - left + 1
		count += section / 2
		seclen << section
		right += 1
		left = right
	end

	if s[0] == s[l - 1]
		beg = seclen[0];
		en = seclen[seclen.length - 1]
		border = beg + en

		beg /= 2;
		en /= 2;
		border /= 2;
		middle = count - beg - en
		puts beg + (middle * k) + (border * (k - 1)) + en
	else
		puts count * k
	end
end