S = gets.chomp!
K = gets.to_i

count = 0
past = ''
S.each_char.with_index do |c, i|
  if past != c && c == S[i + 1]
    count += 1
    past = c
  else
    past = ''
  end
end

if  S.size > 2 && S[0] == S[-1]
  if  S[-1] == S[-2]
    puts (count - 1) * K + K
  else
    puts count * K + K
  end
else
  puts count * K
end
