#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 + 5;
long long val[MAX_N][MAX_N], dp[MAX_N][MAX_N][MAX_N];
int n, a[MAX_N], poi, c[MAX_N];
void read_input() {
  cin >> n;
  string s;
  cin >> s;
  a[0] = 1;
  for (int i = 1; i < n; i++)
    if (s[i] == s[i - 1])
      a[poi]++;
    else
      a[++poi] = 1;
  poi++;
  for (int i = 1; i <= n; i++) cin >> c[i];
}
void prep() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      val[i][j] = val[i][j - 1];
      if (i >= j) val[i][j] = max(val[i][j], val[i - j][j] + c[j]);
    }
}
void solve() {
  prep();
  for (int dif = 0; dif < poi; dif++)
    for (int i = 0; i + dif < poi; i++) {
      int j = i + dif;
      for (int x = 0; x <= n; x++) {
        dp[i][j][x] = dp[i + 1][j][0] + val[x + a[i]][n];
        for (int k = i + 2; k <= j; k += 2)
          dp[i][j][x] =
              max(dp[i][j][x], dp[i + 1][k - 1][0] + dp[k][j][x + a[i]]);
      }
    }
}
void print_output() { cout << dp[0][poi - 1][0]; }
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  read_input();
  solve();
  print_output();
}
