s = gets.chomp.split('')
k = gets.chomp.to_i
# 一つ前の文字が変更したものであれば'c', でなければ'n'
if s.length == 1
    puts k / 2
    exit
end

pre = 'n'
cnt = 0

1.upto((s.length)-1) do |i|
    if pre == 'n' && s[i] == s[i-1]
        cnt += 1
        pre = 'c'
    else
        pre = 'n'
    end
end
if s[0] == s[-1] && pre == 'n'
    puts (cnt+1)*k - 1
else
    puts cnt*k
end