S = gets.to_s.chomp
K = gets.to_i
times = 0
count = 1
100.times do |i|
  if S[i] != nil
    if S[i] == S[i+1]
      count += 1
    else
      times += count/2
      count = 1
    end
  end
end

puts times * K