S = gets.chomp
size = S.size
K = gets.chomp.to_i
s2 = Array.new(2*size)
for x in 0...size do
    s2[x] = S[x]
    s2[x+size] = S[x]
end

a1 = 0
i = 1
while i < size
    if S[i] == S[i-1]
        a1 += 1
        i += 1
    end
    i += 1
end

if K == 1
    puts a1
    exit
end

a2 = 0
i = 1
while i < 2 * size
    if s2[i] == s2[i-1]
        a2 += 1
        i += 1
    end
    i += 1
end

dif = a2 - a1
answer = a1 + dif * (K-1)
puts answer