def solve(r, s, p, t) -> int:

    R, S, P = 0, 1, 2



    n = len(t)

    dp = [[0] * 3 for _ in range(n + 1)]



    for i, c in enumerate(t, 1):

        dp[i][R] = max(dp[i - 1][S], dp[i - 1][P]) + (r if c == 's' else 0)

        dp[i][S] = max(dp[i - 1][P], dp[i - 1][R]) + (s if c == 'p' else 0)

        dp[i][P] = max(dp[i - 1][R], dp[i - 1][S]) + (p if c == 'r' else 0)



    return max(dp[n])





def main():

    n, k = list(map(int, input().split()))

    r, s, p = list(map(int, input().split()))

    t = eval(input())



    ret = 0

    for i in range(k):

        ti = t[i::k]

        ret += solve(r, s, p, ti)



    print(ret)





if __name__ == '__main__':

    main()



# mod Kで小問題に分割して、

# 独立なk個の問題を解く

def main():

    N, K = list(map(int, input().split()))

    R, S, P = list(map(int, input().split()))

    T = eval(input())



    score = {'r': P, 's': R, 'p': S}



    ret = 0

    for r in range(K):

        i = r

        p = ''

        while i < N:

            if T[i] == p:

                p = ''

            else:

                ret += score[T[i]]

                p = T[i]

            i += K

    print(ret)





if __name__ == '__main__':

    main()

def solve(r, s, p, t) -> int:
    R, S, P = 0, 1, 2
    n = len(t)
    dp = [[0] * 3 for _ in range(n + 1)]
    for i, c in enumerate(t, 1):
        dp[i][R] = max(dp[i - 1][S], dp[i - 1][P]) + (r if c == "s" else 0)
        dp[i][S] = max(dp[i - 1][P], dp[i - 1][R]) + (s if c == "p" else 0)
        dp[i][P] = max(dp[i - 1][R], dp[i - 1][S]) + (p if c == "r" else 0)
    return max(dp[n])


def main():
    n, k = list(map(int, input().split()))
    r, s, p = list(map(int, input().split()))
    t = eval(input())
    ret = 0
    for i in range(k):
        ti = t[i::k]
        ret += solve(r, s, p, ti)
    print(ret)


if __name__ == "__main__":
    main()
# mod Kで小問題に分割して、
# 独立なk個の問題を解く

def main():
    N, K = list(map(int, input().split()))
    R, S, P = list(map(int, input().split()))
    T = eval(input())
    score = {"r": P, "s": R, "p": S}
    ret = 0
    for r in range(K):
        i = r
        p = ""
        while i < N:
            if T[i] == p:
                p = ""
            else:
                ret += score[T[i]]
                p = T[i]
            i += K
    print(ret)


if __name__ == "__main__":
    main()

-def solve(r, s, p, t) -> int: -    R, S, P = 0, 1, 2 -    n = len(t) -    dp = [[0] * 3 for _ in range(n + 1)] -    for i, c in enumerate(t, 1): -        dp[i][R] = max(dp[i - 1][S], dp[i - 1][P]) + (r if c == "s" else 0) -        dp[i][S] = max(dp[i - 1][P], dp[i - 1][R]) + (s if c == "p" else 0) -        dp[i][P] = max(dp[i - 1][R], dp[i - 1][S]) + (p if c == "r" else 0) -    return max(dp[n]) - - -    n, k = list(map(int, input().split())) -    r, s, p = list(map(int, input().split())) -    t = eval(input()) +    N, K = list(map(int, input().split())) +    R, S, P = list(map(int, input().split())) +    T = eval(input()) +    score = {"r": P, "s": R, "p": S} -    for i in range(k): -        ti = t[i::k] -        ret += solve(r, s, p, ti) +    for r in range(K): +        i = r +        p = "" +        while i < N: +            if T[i] == p: +                p = "" +            else: +                ret += score[T[i]] +                p = T[i] +            i += K -# mod Kで小問題に分割して、 -# 独立なk個の問題を解く