import Data.List
import Data.Maybe

main = print =<< sol <$> get <*> get <*> getLine

get = fmap read . words <$> getLine

sol [n,k] [r,s,p] t = go 0 z (t++z)
  where
  z = replicate k ' '
  go c [] _ = c
  go c q u  = go c' q' u'
    where
    c' = c + sum (zipWith scr q' u)
    q' = zipWith3 hnd q u u'
    u' = drop k u
  scr 'p' 'r' = p
  scr 'r' 's' = r
  scr 's' 'p' = s
  scr  _   _  = 0

hnd h 'r' f = if h/='p' then 'p' else chs f "rs"
hnd h 's' f = if h/='r' then 'r' else chs f "sp"
hnd h 'p' f = if h/='s' then 's' else chs f "rp"

chs x = fromJust . find (/= sup x)

sup 'r' = 'p'
sup 's' = 'r'
sup 'p' = 's'
sup  _  = ' '
