#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
int f[155][155][155];
int g[155][155];
int h[155][155];
int val[155];
char ss[155];
int gunc(int, int);
int func(int, int, int);
int hunc(int l, int r) {
  if (h[l][r] != -1) return h[l][r];
  int res = max(gunc(l, r), 0);
  for (int i = l; i <= r - 1; i++) {
    res = max(res, hunc(l, i) + hunc(i + 1, r));
  }
  return h[l][r] = res;
}
int gunc(int l, int r) {
  if (g[l][r] != -1) return g[l][r];
  if (l == r) {
    return g[l][r] = val[1] == -1 ? -INF : val[1];
  }
  if (l > r) {
    return g[l][r] = 0;
  }
  int res = -INF;
  for (int i = 1; i <= r - l + 1; i++) {
    if (val[i] == -1) continue;
    res = max(res, func(l, r, i) + val[i]);
  }
  return g[l][r] = res;
}
int func(int l, int r, int len) {
  if (f[l][r][len] != -1) return f[l][r][len];
  if (len <= 0) {
    return f[l][r][len] = gunc(l, r);
  }
  if (l == r) {
    return f[l][r][len] = 0;
  }
  if (l > r) {
    return f[l][r][len] = 0;
  }
  int res = -INF;
  for (int i = l; i <= r - 1; i++) {
    if (len > i - l + 1) continue;
    res = max(res, func(l, i, len) + gunc(i + 1, r));
  }
  for (int i = r; i >= l + 1; i--) {
    if (len > r - i + 1) continue;
    res = max(res, func(i, r, len) + gunc(l, i - 1));
  }
  if (ss[l] == ss[r] && len >= 2) res = max(res, func(l + 1, r - 1, len - 2));
  return f[l][r][len] = res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", val + i);
  }
  memset(g, -1, sizeof(g));
  memset(f, -1, sizeof(f));
  memset(h, -1, sizeof(h));
  scanf("%s", ss + 1);
  printf("%d\n", hunc(1, n));
  return 0;
}
