require 'pp'

s = gets.chomp!
k = gets.chomp!.to_i
chs = s.chars

chunk = chs.chunk_while{|i, j| i == j }.to_a
if chunk.length >= 2 && chunk[0][0] == chunk[-1][0]
    chunk[0] = chunk[0] + chunk[-1] 
    chunk.delete_at(-1)
end

total = 0
chunk.each do |ch|
    total += ch.length / 2
end

puts total * k
