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

get = fmap read . words <$> getLine

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