s = gets.chomp.split('')
k = gets.chomp.to_i
cnt = 0
skip = false
0.upto(s.length - 1) do |i|
    if skip
        skip = false
        next
    end
    if i == s.length-1 && s[i] == s[0]
       cnt += 1
       next
    end
    if s[i] == s[i+1]
        cnt += 1
        skip = true
    else
        skip = false
    end
end

puts cnt * k
