program prediction_and_Restriction
    implicit none
    integer(4):: n, k, r, s, p
    integer(8):: tot = 0
    integer(4):: i, j
    character(100000):: t
    logical, allocatable:: can_win(:)

    read*, n, k
    read*, r, s, p
    read*, t
    allocate(can_win(n))


can_win(:) = .true.

    do i=k+1,n
            if (t(i:i) /= t(i-k:i-k)) cycle
            if (can_win(i-k)) can_win(i) = .false.
    end do

    tot = 0
    do i=1,n
        if (.not.can_win(i)) cycle
        if (t(i:i) == 'r') tot = tot + p
        if (t(i:i) == 'p') tot = tot + s
        if (t(i:i) == 's') tot = tot + r
    end do
    
    print*, tot
end program prediction_and_Restriction
