s = gets.chomp.split("")
k = gets.to_i
s_double = s * 2

increment_when_odd = 0
(1...s.size).each do |i|
  if s[i - 1] == s[i]
    s[i] = 'A'
    increment_when_odd += 1
  end
end

increment_when_even = 0
(1...s_double.size).each do |i|
  if s_double[i - 1] == s_double[i]
    s_double[i] = 'A'
    increment_when_even += 1
  end
end
increment_when_even -= increment_when_odd

even = k / 2
odd = k.odd? ? even + 1 : even

puts increment_when_odd * odd + increment_when_even * even
