program prediction_and_restriction
  implicit none
  integer :: n, k, r, s, p, i, x = 0
  character(100000) :: t
  read(*,*) n, k
  read(*,*) r, s, p
  read(*,*) t
  do i = k+1, n
    if (t(i:i) == t(i-k:i-k)) then
      t(i:i) = 'x'
    end if
  end do
  do i = 1, n
    select case (t(i:i))
    case ('r')
      x = x+p
    case ('s')
      x = x+r
    case ('p')
      x = x+s
    end select
  end do
  write(*,'(i0)') x
end program prediction_and_restriction