S = gets.chomp.chars
K = gets.to_i

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

last_replaced = false
count = 0
prev = '*'
S.each.with_index do |ch, i|
  if prev == ch
    prev = '*'
    count += 1
  else
    if i == S.size - 1 && ch == S.first
      count += 1
      last_replaced = true
    else
      prev = ch
    end
  end
end
ans = (count * K) + (last_replaced ? -1 : 0)
puts ans
