s = gets.chomp
k = gets.to_i
n = s.size

if n == 1
  puts k/2
else
  tmp = 0
  (0..n-1).each do |i|
    next if s[i] == '*'

    if s[i] == s[i+1]
      s[i+1] = '*'
      tmp += 1
    end
  end

  tmp2 = 0
  if s[-1] != '*' && s[0] == s[-1]
    tmp2 = 1
  end

  puts tmp * k + tmp2 * (k-1)
end
