#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793238463;
long long reward[109], a[109];
long long dp[109][109][109];
long long sol(int i, int j, long long prev) {
  if (i == j) return reward[a[i] + prev];
  long long &ret = dp[i][j][prev];
  if (ret != -1) return ret;
  ret = reward[a[i] + prev] + sol(i + 1, j, 0);
  for (int k = i + 2; k <= j; k += 2) {
    ret = max(ret, sol(i + 1, k - 1, 0) + sol(k, j, a[i] + prev));
  }
  return ret;
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = (1); i <= (n); i++) cin >> reward[i];
  for (int i = (1); i <= (n); i++) {
    for (int j = (1); j <= (i); j++) {
      int k = i - j;
      reward[i] = max(reward[i], reward[j] + reward[k]);
    }
  }
  int idx = 0, cnt = 1;
  for (int i = (1); i < (n); i++) {
    if (s[i] == s[i - 1])
      cnt++;
    else
      a[idx++] = cnt, cnt = 1;
  }
  if (cnt) a[idx++] = cnt;
  memset((dp), (-1), sizeof(dp));
  cout << sol(0, idx - 1, 0) << '\n';
  return 0;
}
