      PROGRAM predictionAndrestriction
      IMPLICIT NONE
      integer(16) :: n,r,s,p,k
      character(:),allocatable :: t
      character(:),allocatable :: sub(:)
      integer(16) :: i,index,ans,rsp(3)
      integer(16),allocatable :: len(:),dp(:,:)
      
      read*,n,k
      read*,r,s,p
      allocate( character(n) :: t )
      allocate( character(n) :: sub(k) )
      allocate( len(k) )
      read*,t(1:n)
      
      len(:) = 0
      do i = 1,n
        index = mod(i,k)
        if( index==0 ) index = k
        
        len(index) = len(index) + 1
        sub(index)(len(index):len(index)) = t(i:i)
      end do
      
      allocate( dp(3,0:maxval(len)) )
      ans = 0
      do index = 1,k
        if( len(index)==0 )cycle
        if( len(index)==1 )then
          ans = ans + max(r,s,p)
          cycle
        end if
        dp(:,:) = 0
        do i = 1,len(index)
          rsp(:) = 0
          select case( sub(index)(i:i) )
          case( 'r' )
            rsp(3) = p
          case( 's' )
            rsp(1) = r
          case( 'p' )
            rsp(2) = s
          end select
          dp(1,i) = max( dp(2,i-1)+rsp(1),dp(3,i-1)+rsp(1) )
          dp(2,i) = max( dp(1,i-1)+rsp(2),dp(3,i-1)+rsp(2) )
          dp(3,i) = max( dp(1,i-1)+rsp(3),dp(2,i-1)+rsp(3) )
          
        end do
        ans = ans + maxval( dp(:,len(index)) )
      end do
      
      
      
      print*,ans
      stop
      
      
      !debugg
      print*,n,k
      print*,r,s,p
      print*,t(1:n)
      do i = 1,k
        print*,sub(i)(1:len(i))
      end do
      
      END PROGRAM