S = gets.chomp
K = gets.to_i

def count(s)
  res = 0
  s.scan(/(.)\1+/){res += $&.size/2}
  res
end

single = count(S)
double = count(S+S)
if single * 2 == double
  p single * K
else
  p (single + 1) * K - 1
end