s=gets.chomp
k=gets.chomp.to_i

n=0
s.each_char.with_index do |c,i|
  next if i == 0
  n+=1 if s[i-1]==c
end

a=0
s.each_char.with_index do |c,i|
  next if i == 0
  break if s[0] != c
  a+=1
end

b=0
s.reverse.each_char.with_index do |c,i|
  next if i == 0
  break if b[0] != c
  b+=1
end

puts ((n*k)-(a/2+b/2-((a+b)/2)*(k-1)))