s = gets.chomp.split("")
k = gets.to_i
if s.size == 1
  puts k / 2
else
  change_count = 0
  (1...s.size).each do |i|
    if s[i - 1] == s[i]
      s[i] = 'A'
      change_count += 1
    end
  end
  puts change_count * k
end
