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 == 1
    puts chunk[0].length * k / 2
    exit 0
end

# 一回目
total = 0
chunk.each do |ch|
    total += ch.length / 2
end
#pp total
# 2回目以降
sub_total = 0
if k >= 2
    chunk.each do |ch|
        sub_total += ch.length / 2
    end
    if chunk[0][0] == chunk[-1][0]
        if chunk[0].length % 2 == 1 && chunk[-1].length % 2 == 1
            sub_total += 1
        end
    end
end

puts total + sub_total * (k-1)

