S=gets.chomp
K=gets.to_i
rle=S.chars.inject([]){|s,c|
	if s.empty? || s[-1][0]!=c then
		s << [c,1]
	else
		s[-1][1]+=1
	end
	s
}
ans=rle.map{|x|x[1]/2}.inject(:+)*K
if rle.size==1 then
	ans=S.size()*K/2
elsif rle[0][0]==rle[-1][0] then
	ans+=(rle[0][1]%2+rle[-1][1]%2)/2*(K-1)
end
p ans