void main() {
	int mi(dchar t) {
		if(t == 'r') return 0;
		if(t == 's') return 1;
		else return 2;
	}
	dchar im(int t) {
		if(t == 0) return 'r';
		if(t == 1) return 's';
		else return 'p';
	}
	auto ip = readAs!(int[]), N = ip[0], K = ip[1];
	auto scores = readAs!(int[]); // r s p
	auto T = rs.map!(v => mi(v)).array;
	// r s p => 0 1 2

	auto dp = new long[][](N+1, 3);
	// dp[i][i-K+1回前の手]
	// -1: 初期化
	foreach(v; dp) v[] = -1;
	dp[0][] = 0;
	
	
	bool win(int a, int b) {
		if(a == 0 && b == 1) return true;
		if(a == 1 && b == 2) return true;
		if(a == 2 && b == 0) return true;
		return false;
	}
	long solve(int i, int t) {
		if(i < 0 || i > N) return 0;
		if(dp[i][t] >= 0) return dp[i][t];
		long tmp;
		tmp = max(tmp, solve(i-1, (t+1)%3));
		tmp = max(tmp, solve(i-1, (t+2)%3));
		if(win(t, T[i-1])) {
			tmp += scores[t];
		}
		debug writefln("%d, %s: %d", i, im(t), tmp);
		return dp[i][t] = tmp;
	}
	solve(N, 0);
	solve(N, 1);
	solve(N, 2);
	writeln(dp[N].reduce!max);
	debug dp.each!writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}