use std::collections::HashMap;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
  }

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
  }

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

// 最大公約数
fn gcd(a: i64, b: i64) -> i64 {
    let mut aa: i64 = if a > b { a } else { b };
    let mut bb: i64 = if a > b { b } else { a };
    while bb != 0 {
        let tmp = bb;
        bb = aa % tmp;
        aa = tmp;
    }
    return aa;
}

// 最小公倍数
fn lcm(a: i64, b: i64) -> i64 {
    a / gcd(a, b) * b
}

const LARGE_PRIME: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        k: usize,
        r: usize,
        s: usize,
        p: usize,
        t: String
    }

    const ROCK: usize = 1;
    const SEASORS: usize = 2;
    const PAPER: usize = 3;
    const NONE: usize = 4;

    let mut junken_array = vec![NONE; n];

    let mut hand_Score = HashMap::new();
    hand_Score.insert(ROCK, r);
    hand_Score.insert(SEASORS, s);
    hand_Score.insert(PAPER, p);

    let mut win_score = HashMap::new();
    win_score.insert(ROCK, p);
    win_score.insert(SEASORS, r);
    win_score.insert(PAPER, s);

    fn win_hand(hand: char) -> usize {
        if hand == 'r' {
            return PAPER;
        }
        if hand == 's' {
            return ROCK;
        }
        if hand == 'p' {
            return SEASORS;
        }
        NONE
    }

    fn hand(hand: char) -> usize {
        if hand == 'r' {
            return ROCK;
        }
        if hand == 's' {
            return SEASORS;
        }
        if hand == 'p' {
            return PAPER;
        }
        NONE
    }

    let mut score = 0;
    let tt = t.chars().collect::<Vec<char>>();
    for i in 0..n {
        let prohibit = if i >= k { junken_array[i - k] } else { NONE };

        if prohibit != win_hand(tt[i]) {
            junken_array[i] = win_hand(tt[i]);
            score += hand_Score[&junken_array[i]];
        } else {
            let after_k = if i + k < n { tt[i + k] } else { 'a' };

            if win_hand(after_k) == hand(tt[i]) {
                junken_array[i] = hand(after_k);
            } else {
                junken_array[i] = hand(tt[i]);
            }
        }
    }

    println!("{}", score);
}


Measured memory_bytes: 4352