s = gets.chomp
k = gets.to_i

cnt = 0
changed = Array.new(s.size, false)
(0..s.size-2).each do |i|
  if !changed[i] && s[i] == s[i+1]
    cnt += 1
    changed[i+1] = true
  end
end

adj_cnt = 0
if s[0] == s[s.size-1] && !changed[s.size-1]
  adj_cnt = 1
end

puts cnt * k + adj_cnt * (k-1)
