def count_cont(s)
    bef = ''
    cnt = 0
    s.each_char do |c|
        if c == bef
            cnt += 1
            bef = 'Z'
        else
            bef = c
        end
    end
    #puts cnt
    cnt
end

def aa
    s = gets.chomp
    k = gets.chomp.to_i

    if s.length == 1
        puts (k/2.0).floor
        exit
    end

    if s.split("").uniq.length == 1
        if s.length%2 == 0
            puts s.length/2 * k
        else
            if k == 1
                puts s.length/2
            elsif k%2 == 0
                puts k/2 * s.length
            else
                puts k/2 * s.length + s.length/2
            end
        end
        exit
    end

    cnt1 = count_cont(s)
    if k == 1
        puts cnt1
    elsif k%2 == 0
        cnt2 = count_cont(s+s)
        puts (k-1)*(cnt2-cnt1) + cnt1
    else
        cnt2 = count_cont(s+s)
        puts (k-1)*(cnt2-cnt1) + cnt1
    end
end

aa