s = gets.chomp
k = gets.to_i
l = s.length

ans = 0
count = 0
x = 0
(l-1).times do |i|
    if s[i] == s[i+1]
        count == 0 ? x += 1 : count += 1
    else
        ans += count / 2
        count = 1
    end
end

x += 1 if x != 0
puts ans * k + x / 2 + count / 2 + (x + count) / 2 * (k - 1)