program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: k,i,n,a1,a2
    character(100):: s
    character(200):: s2

    read*, s
    read*, k
    n = len_trim(s)
    s2 = trim(s) // trim(s)

    a1 = serch(s,n)
    a2 = serch(s2,2*n)

    print'(i0)', a1*k + (1)*(k-1)

contains
    function serch(str,n) result(ret)
        character(*):: str
        integer(int64):: n,ret
        integer(int64):: i

        ret = 0
        do i=2,n
            if (str(i:i) == str(i-1:i-1)) then
                ret=ret+1
                str(i:i)='0'
            end if
        end do
    end function
end program name