#include <bits/stdc++.h>                                                                        
using namespace std;                                                                            
using ll = long long;                                                                           
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }         
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }         
#define rep(i,n) for (int i=0; i< (n); ++i)                                                     
typedef pair<int, int> P;                                                                       
ll dp[100000+5][3];                                                                             
                                                                                                
int main() {                                                                                    
  int n, k;                                                                                     
  cin >> n >> k;                                                                                
  int r, s, p;                                                                                  
  cin >> r >> s >> p;                                                                           
  string t;                                                                                     
  cin >> t;                                                                                     
  ll sum = 0;                                                                                   
  string comp = "";                                                                             
  rep(i,n) {                                                                                    
    if (i-k >= 0) {                                                                             
      if (t[i] == comp[i-k]) {                                                                  
        comp += 't';                                                                            
        continue;                                                                               
      }                                                                                         
    }                                                                                           
    if (t[i] == 'r') {                                                                          
      sum += p;                                                                                 
      comp += 'r';                                                                              
    } else if (t[i] == 's') {                                                                   
      sum += r;                                                                                 
      comp += 's';                                                                              
    } else if (t[i] == 'p') {                                                                   
      sum += s;                                                                                 
      comp += 'p';                                                                              
    }                                                                                           
    //cout << comp << endl;                                                                     
  }                                                                                             
  cout << sum << endl;                                                                          
  return 0;                                                                                     
                                                                                                
}                                                                                               
    

Measured memory_bytes: 640