#include <bits/stdc++.h>
using namespace std;
int const N = 155;
long long const INF = 1e12;
int n;
long long c[N], dp[N][N][N][2];
int w[N][N][N][2];
string s;
long long rec(int l, int r, int len, int t) {
  if (l > r) {
    if (t)
      return c[len];
    else
      return max(0LL, c[len]);
  }
  if (w[l][r][len][t]) return dp[l][r][len][t];
  w[l][r][len][t] = 1;
  long long ret = -INF;
  if (!t) ret = 0;
  int mr = (len % 2);
  int tr = (len <= 1 ? 0 : 1);
  tr = max(tr, t);
  int tl = (len <= 0 ? 0 : 1);
  tl = max(tl, t);
  for (int i = l; i <= r; ++i) {
    if (!mr || s[l - 1] == s[i]) {
      long long rp = rec(i + 1, r, 0, tr);
      long long lp = rec(l, i - 1, 0, tl);
      long long cp = c[len + 1];
      ret = max(ret, lp + rp + cp);
    }
  }
  for (int i = l; i <= r; ++i) {
    if (!mr || s[l - 1] == s[i]) {
      if (mr) {
        long long rp = rec(i + 1, r, 0, tr);
        long long lp = rec(l, i - 1, len + 1, tl);
        ret = max(ret, lp + rp);
      } else {
        long long rp = rec(i + 1, r, len + 1, tr);
        long long lp = rec(l, i - 1, 0, tl);
        ret = max(ret, lp + rp);
      }
    }
  }
  dp[l][r][len][t] = ret;
  return ret;
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
    if (c[i] == -1) c[i] = -INF;
  }
  cin >> s;
  long long ans = rec(0, n - 1, 0, 0);
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
