fun main(args: Array<String>) {
    val (n, k) = readIntegerList()
    val (r, s, p) = readIntegerList()
    val t = readLine()!!
    val dp = Array(n + 1) { LongArray(3) }
    for (i in 1..n) {
        val pre = Math.max(i - k, 0)
        dp[i][0] = Math.max(dp[pre][1], dp[pre][2]) + if (t[i - 1] == 's') r else 0
        dp[i][1] = Math.max(dp[pre][2], dp[pre][0]) + if (t[i - 1] == 'p') s else 0
        dp[i][2] = Math.max(dp[pre][0], dp[pre][1]) + if (t[i - 1] == 'r') p else 0
    }
    var ans = 0L
    for (i in n downTo (n - k + 1)) {
        ans += dp[i].max()!!
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)
