S = gets.chomp
K = gets.to_i

# 2,3 -> 1
# 3,4 -> 2

r = [1]
combo = false
S.split("").each_with_index do |c, i|
    next if i == 0
    if S[i] == S[i-1]
        r[-1] += 1
    else
        r.push(1)
    end
end


if r.length == 1
    puts r[0]*K/2
    exit
end

ret = r.map {|e| e /2 }.inject(:+)
ret *= K

if S[0] == S[-1] && r[0].odd? && r[1].odd?
    ret += (K-1)
end

puts ret