S=gets.chomp
K=gets.chomp.to_i

if S.size == 1
  puts K/2
else
  have_to_change_count = S.scan(/(.)\1+?/).size
  if S[0] == S[-1] && S[0] != S[1] && S[-1] != S[-2]
    puts ((have_to_change_count + 1) * K)
  else
    puts (have_to_change_count * K)
  end
end
