#include <bits/stdc++.h>
using namespace std;
const int N = 155;
const int INF = 1e9;
int n, a[N];
string s;
int memo[N][N][N / 2][2];
int go(int l, int r, int down, bool all) {
  int &res = memo[l][r][down][all];
  if (res != -1) return res;
  if (l >= r) {
    if (down == 0) return 0;
    if (a[2 * down] == -1) return -INF;
    return a[2 * down];
  }
  res = -INF;
  if (!all) res = max(res, go(l + 1, r, 0, false));
  if (a[1] != -1) res = max(res, a[1] + go(l + 1, r, down, all));
  if (down && a[2 * down] != -1)
    res = max(res, go(l, r, 0, true) + a[2 * down]);
  if (a[2 * down + 1] != -1)
    res = max(res, go(l + 1, r, 0, true) + a[2 * down + 1]);
  for (int i = (int)(l + 1); i < ((int)r); i++)
    if (s[i] == s[l]) {
      res = max(res, go(l + 1, i, down + 1, true) + go(i + 1, r, 0, all));
      res = max(res, go(l + 1, i, 1, true) + go(i + 1, r, down, true));
    }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  a[0] = -1;
  for (int i = 0; i < (int)(n); i++) cin >> a[i + 1];
  cin >> s;
  memset(memo, -1, sizeof memo);
  cout << go(0, n, 0, false) << endl;
  return 0;
}
