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

get = fmap read . words <$> getLine

sol [n,k] [r,s,p] = go (replicate k ' ') 0
  where
  go [] c _ = c
  go qs c t = go qs' c' t'
    where
    qs' = zipWith hnd qs t
    c' = c + sum (zipWith scr qs t)
    t' = drop k t
  hnd h 'r' = if h=='p' then 'r' else 'p'
  hnd h 's' = if h=='r' then 's' else 'r'
  hnd h 'p' = if h=='s' then 'p' else 's'
  scr h 'r' = if h=='p' then 0 else p
  scr h 's' = if h=='r' then 0 else r
  scr h 'p' = if h=='s' then 0 else s
