import std.algorithm, std.array, std.conv, std.range, std.stdio, std.string;
void main()
{
    auto buf = readln.chomp.split.to!(int[]);
    auto nGames = buf[0], kRestrict = buf[1];
    buf = readln.chomp.split.to!(int[]);
    auto t = (cast(ubyte[])(readln.chomp)).map!(_ => [
            'r': Hand.rock,
            's': Hand.scissors,
            'p': Hand.paper
    ][_]).array;
    solve(nGames, kRestrict, buf, t).writeln;
}
long solve(int nGames, int kRestrict, int[] scores, Hand[] machine)
{
    long ret;
    foreach (i; 0..kRestrict)
    {
        ret += solve1(scores, machine.stride(kRestrict).array);
        machine.popFront;
    }
    return ret;
}
long solve1(int[] scores, Hand[] machine)
{
    // dp[i][j] := max{score; i-th hand = j}
    auto dp = new long[3][machine.length];
    dp[0][] = iota(3).map!(_ => scores.score(_, machine[0])).array[];
    foreach (i; 1..machine.length)
    {
        foreach (j; 0..3)
        {
            foreach (k; 0..3)
                if (j != k)
                    dp[i][j] = max(dp[i][j], dp[i-1][k]);
            dp[i][j] += scores.score(j, machine[i]);
        }
    }
    return dp[machine.length - 1].array.reduce!max;
}
enum Hand
{
    rock, scissors, paper
}
long score(int[] scores, int hand, int machine)
{
    if ((hand + 4 - machine) % 3) return 0;
    return scores[hand];
}
unittest
{
    with (Hand)
    {
        assert (score([8, 7, 6], rock, rock) == 0);
        assert (score([8, 7, 6], rock, scissors) == 8);
        assert (score([8, 7, 6], rock, paper) == 0);
        assert (score([8, 7, 6], scissors, rock) == 0);
        assert (score([8, 7, 6], scissors, scissors) == 0);
        assert (score([8, 7, 6], scissors, paper) == 7);
        assert (score([8, 7, 6], paper, rock) == 6);
        assert (score([8, 7, 6], paper, scissors) == 0);
        assert (score([8, 7, 6], paper, paper) == 0);
    }
}
