program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64)::n,k,r,s,p,i,ans
    character(:),allocatable:: t
    logical,allocatable:: w(:)

    read*, n,k
    read*, r,s,p
    allocate(character(n):: t)
    read*, t
    allocate(w(n))

    ans=0
    do i=1,k
        ans=ans+win(t(i:i))
    end do
    w(1:k) = .true.
    w(k+1:) = .false.
    do i=k+1,n
        if (t(i:i)==t(i-k:i-k) .and. w(i-k)) cycle
        ans=ans+win(t(i:i))
        w(i) = .true.
    end do
    print'(i0)', ans

contains
    function win(ss) result(ret)
        character(1):: ss
        integer(int64):: ret

        if (ss=='r') then
            ret = p
        else if (ss=='p') then
            ret = s
        else
            ret = r
        end if
    end function
end program name