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

ans = 0
count = 0
x = 1
(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

if x == l
    puts l * k / 2
elsif s[0] == s[-1]
    puts ans * k + x / 2 + count / 2 + (x + count) / 2 * (k - 1)
else
    puts ans * k + (x / 2 + count / 2) * k
end
