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

ans = 0
(1..n-1).each do |i|
  if s[i-1] == s[i] && s[i-1] != '*'
    s[i] = '*'
    ans += 1
  end
end
if k == 1
else
  if s[0] == s[n-1] && s[n-1] != '*'
    ans += 1
  end
end
puts ans * k
