s = gets.chomp.split(//)
n = gets.to_i
size = s.size
bef = s[0]
count = 0
(1...size).each do |i|
  check = 0
  if s[i] == bef
    count += 1
    check = 1
  end
  bef = s[i]
  bef = "." if check == 1
end
count += 1 if s[-1] == s[0] && s[-1] != s[-2]
puts count * n