fun main(args: Array<String>) {
    val (n, k) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val (r, s, p) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val tList = readLine() ?: return

    fun rps(
        tList: String,
        winT: Char,
        evenT: Char,
        index: Int,
        k: Int,
        win: Int,
        history: MutableList<Char>
    ) =
        if (index < k) {
            history.add(winT)
            win
        } else {
            val h = history[index - k]
            when {
                h != winT -> {
                    history.add(winT)
                    win
                }
                h == tList[index - k] -> {
                    history.add(winT)
                    win
                }
                else -> {
                    history.add(evenT)
                    0
                }
            }
        }

    var total = 0L
    val history = mutableListOf<Char>()
    tList.forEachIndexed { i, t ->
        when (t) {
            'r' -> {
                total += rps(tList, 'p', 'r', i, k, p, history)
            }
            's' -> {
                total += rps(tList, 'r', 's', i, k, r, history)
            }
            'p' -> {
                total += rps(tList, 's', 'p', i, k, s, history)
            }
        }
    }
    println(total)
}