S, K = gets.chomp, gets.to_i
a = S.scan(/((.)\2*)/).map{|_1,| _1.size }
if a.size == 1
	p a[0]*K/2
else
	isCyc = S[0] == S[-1]
	if isCyc
		hosei = a[0]/2 + a[-1]/2
		a[-1] += a.shift
		hosei -= a[-1]/2
	else
		hosei = 0
	end
	p K*a.inject(0){|acc,_| acc+_/2 } + hosei
end
