def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    #from collections import defaultdict

    from itertools import combinations, permutations, accumulate, groupby

    #from itertools import product

    from bisect import bisect_left,bisect_right

    from heapq import heapify, heappop, heappush

    from math import floor, ceil

    #from operator import itemgetter



    #inf = 10**17

    #mod = 10**9 + 7



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

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

    t = input().rstrip()

    hasi = []



    res = 0

    for i in range(n):

        if t[i]=='r':

            a = r

            b = 'p'

        if t[i]=='s':

            a = s

            b = 'r'

        if t[i]=='p':

            a = p

            b = 's'

        if i<k:

            res += a

            hasi.append(b)

        else:

            if t[i]==t[i-k] and b in hasi[i-k]:

                hasi.append('x')

                continue

            else:

                res += a

                hasi.append(b)

    print(res)





if __name__ == '__main__':

    main()
def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    #from collections import defaultdict

    from itertools import combinations, permutations, accumulate, groupby, product

    from bisect import bisect_left,bisect_right

    from heapq import heapify, heappop, heappush

    from math import floor, ceil

    #from operator import itemgetter



    #inf = 10**17

    #mod = 10**9 + 7



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

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

    t = list(input().rstrip())

    score = []

    for i in t:

        if i == 'r':

            score.append(p)

        if i == 's':

            score.append(r)

        if i == 'p':

            score.append(s)



    res = sum(score)

    for i in range(k, n):

        if t[i] == t[i-k]:

            res -= score[i]

            t[i] = 'u'

    print(res)



if __name__ == '__main__':

    main()
def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque

    # from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby

    # from itertools import product
    from bisect import bisect_left, bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil

    # from operator import itemgetter
    # inf = 10**17
    # mod = 10**9 + 7
    n, k = list(map(int, input().split()))
    s, p, r = list(map(int, input().split()))
    t = input().rstrip()
    hasi = []
    res = 0
    for i in range(n):
        if t[i] == "r":
            a = r
            b = "p"
        if t[i] == "s":
            a = s
            b = "r"
        if t[i] == "p":
            a = p
            b = "s"
        if i < k:
            res += a
            hasi.append(b)
        else:
            if t[i] == t[i - k] and b in hasi[i - k]:
                hasi.append("x")
                continue
            else:
                res += a
                hasi.append(b)
    print(res)


if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque

    # from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left, bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil

    # from operator import itemgetter
    # inf = 10**17
    # mod = 10**9 + 7
    n, k = list(map(int, input().split()))
    r, s, p = list(map(int, input().split()))
    t = list(input().rstrip())
    score = []
    for i in t:
        if i == "r":
            score.append(p)
        if i == "s":
            score.append(r)
        if i == "p":
            score.append(s)
    res = sum(score)
    for i in range(k, n):
        if t[i] == t[i - k]:
            res -= score[i]
            t[i] = "u"
    print(res)


if __name__ == "__main__":
    main()

-    from itertools import combinations, permutations, accumulate, groupby - -    # from itertools import product +    from itertools import combinations, permutations, accumulate, groupby, product -    s, p, r = list(map(int, input().split())) -    t = input().rstrip() -    hasi = [] -    res = 0 -    for i in range(n): -        if t[i] == "r": -            a = r -            b = "p" -        if t[i] == "s": -            a = s -            b = "r" -        if t[i] == "p": -            a = p -            b = "s" -        if i < k: -            res += a -            hasi.append(b) -        else: -            if t[i] == t[i - k] and b in hasi[i - k]: -                hasi.append("x") -                continue -            else: -                res += a -                hasi.append(b) +    r, s, p = list(map(int, input().split())) +    t = list(input().rstrip()) +    score = [] +    for i in t: +        if i == "r": +            score.append(p) +        if i == "s": +            score.append(r) +        if i == "p": +            score.append(s) +    res = sum(score) +    for i in range(k, n): +        if t[i] == t[i - k]: +            res -= score[i] +            t[i] = "u"