#include <bits/stdc++.h>
using namespace std;
long long bestLen[102];
long long dp[102][102][102];
long long solve(vector<int>& groups, int i, int j, int extra) {
  if (i > j) return 0;
  if (dp[i][j][extra] != -1) return dp[i][j][extra];
  long long answer = bestLen[groups[i] + extra] + solve(groups, i + 1, j, 0);
  for (int group = i + 2; group <= j; group += 2) {
    answer = max(answer, solve(groups, i + 1, group - 1, 0) +
                             solve(groups, group, j, extra + groups[i]));
  }
  return dp[i][j][extra] = answer;
}
void prepareBestLen(vector<int>& cost) {
  memset(bestLen, 0, sizeof bestLen);
  memset(dp, -1, sizeof dp);
  for (int len = 1; len < cost.size(); len++) {
    for (int cut = 1; cut <= len; cut++) {
      bestLen[len] = max(bestLen[len], cost[cut] + bestLen[len - cut]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> cost(n + 1);
    for (int i = 1; i < n + 1; i++) cin >> cost[i];
    prepareBestLen(cost);
    vector<int> groups;
    int consec = 0;
    for (int i = 0; i < s.length(); i++) {
      if (i == 0)
        consec++;
      else {
        if (s[i] == s[i - 1])
          consec++;
        else {
          groups.push_back(consec);
          consec = 1;
        }
      }
    }
    groups.push_back(consec);
    cout << solve(groups, 0, (int)groups.size() - 1, 0);
  }
  return 0;
}
