S = gets.chomp!
K = gets.to_i

if S.size == 1
  puts K / 2
  exit
end

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.odd?
  if S[0] == S[-1] && S[-1] == S[-2] &&
      S.split('').uniq.size > 1
    puts count * K
  else
    puts (count + 1) * K - 1
  end
else
  puts count * K
end
