S = gets.chomp
K = gets.to_i

def f(s)
  cnt = 0
  chain = 1
  current = s[0]

  s[1..-1].each_char do |c|
    if current == c
      chain += 1
    else
      cnt += chain / 2
      chain = 1
      current = c
    end
  end

  cnt += chain / 2

  cnt
end

puts f(S) * K
