s = gets.chomp.split('')
k = gets.chomp.to_i

chain_cnt = 1
chain_cnt_list = []

if s.length == 1
    puts k/2
    exit
end

1.upto(s.length-1) do |i|
    if s[i] == s[i-1]
        chain_cnt += 1
    else
        chain_cnt_list << chain_cnt
        chain_cnt = 1
    end
    if i == s.length - 1
        chain_cnt_list << chain_cnt
    end
end

p chain_cnt_list

if chain_cnt_list.length == 1
    puts (s.length * k)/2
    exit
end

tmp = chain_cnt_list.map do |c|
    c > 1 ? c/2 : 0
end.inject(:+)
puts tmp
if s[0] != s[-1]
    puts tmp * k
else
    ans = tmp * k - (k - 1) * ((chain_cnt_list[-1]/2 + chain_cnt_list[0]/2 )- (chain_cnt_list[-1] + chain_cnt_list[0])/2)
    puts ans
end