s = gets.chomp
k = gets.to_i
count = 0

(1..s.length).each do |i|
  str_a = ("a".."z").to_a
  if s[i] == s[i - 1]
    str_a.delete(s[i - 1])
    str_a.delete(s[i + 1])
    s[i] = str_a.pop
    count += 1
  end
end

puts count * k