import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(char, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, k;
    scan(n, k);
    auto point = aryread();

    auto t = readln.chomp.map!(x => "rsp".countUntil(x)).array();
    auto janken = new long[][](n, 3);
    foreach (i; iota(n))
    {
        foreach (j; iota(3))
        {
            long getPoint(long machine, long takahashi)
            {
                if (machine == (takahashi + 1) % 3)
                    return point[takahashi];
                else
                    return 0;
            }

            if (i - k < 0)
                janken[i][j] = getPoint(t[i], j);
            else
                janken[i][j] = max(janken[i - k][(j + 1) % 3], janken[i - k][(j + 2) % 3]) + getPoint(t[i],
                        j);
        }
    }
    // janken.each!(x => x.writeln());
    long ans;
    foreach (i; iota(k))
    {
        ans += janken[$ - 1 - i].reduce!(max);
    }
    ans.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
