      PROGRAM predictionAndRestriction
      IMPLICIT NONE
      integer,parameter :: prec = 8
      integer(prec) :: n,rsp(0:2),k, ans=0
      character(10**5) :: t
      integer(prec) :: i,j, used(10**5),best,tt(10**5)
      
      read*,n,k
      read*,rsp(0:2)
      read*,t
      
      do i = 1,n
        select case( t(i:i) )
        case( 'r' )
          tt(i) = 6
        case( 's' )
          tt(i) = 7
        case( 'p' )
          tt(i) = 8
        end select
      end do
      
        do j = 1,n
          best = mod( tt(j)-1,3 )
          
          if( j-k<=0 )then
            used(j) = best
            ans = ans + rsp( best )
            cycle
          end if
          
          if( best==used(j-k) )then
            if( j+k<=n )then
              used(j) = mod(tt(j+k),3)
            else
              used(j) = mod(best+1,3)
            end if
          else
            used(j) = best
            ans = ans + rsp( best )
          end if
          
        end do
      
      print*,ans
      stop
      
      
      do i = 1,n
        select case( used(i) )
        case(0)
          t(i:i) = 'r'
        case(1)
          t(i:i) = 's'
        case(2)
          t(i:i) = 'p'
        end select
      end do
      print*,t(1:n)
      
      END PROGRAM