#include <bits/stdc++.h>
using namespace std;
void ch_max(int &x, int y) {
  if (x < y) x = y;
}
void ch_min(int &x, int y) {
  if (x > y) x = y;
}
const double pi = acos(-1.0);
const double eps = 1e-9;
const int N = 155;
int a[N], n;
char str[N];
int d[N][N][N], f[N][N][N];
const int ncal = 0x7f7f7f7f;
int cal_f(int s, int t, int m) {
  int i, j, k;
  if (s == 1 && t == 3 && m == 0) {
    int trerse = 0;
  }
  int &ret = f[s][t][m];
  if (ret != ncal) return ret;
  ret = -1;
  if (s > t) {
    ret = a[m];
    return ret;
  }
  int t0, t1, t2;
  if (m > 0) {
    t0 = cal_f(s, t, 0);
    if (t0 != -1 && a[m] != -1) {
      ch_max(ret, t0 + a[m]);
    }
  }
  if (str[s] == str[t]) {
    t1 = 1;
    if (s != t) t1++;
    t2 = cal_f(s + 1, t - 1, m + t1);
    ch_max(ret, t2);
  }
  for (i = s; i < t; ++i) {
    t0 = cal_f(s, i, m);
    t1 = cal_f(i + 1, t, 0);
    if (t0 != -1 && t1 != -1) ch_max(ret, t0 + t1);
    t0 = cal_f(s, i, 0);
    t1 = cal_f(i + 1, t, m);
    if (t0 != -1 && t1 != -1) ch_max(ret, t0 + t1);
  }
  return ret;
}
int cal_d(int s, int t, int m) {
  int i, j, k;
  int &ret = d[s][t][m];
  if (ret != ncal) return ret;
  ret = 0;
  if (s > t) {
    if (a[m] != -1) ret = a[m];
    return ret;
  }
  int t0 = cal_f(s, t, 0), t1, t2;
  if (t0 != -1) {
    ch_max(ret, t0);
    if (a[m] != -1) ch_max(ret, t0 + a[m]);
  }
  if (str[s] == str[t]) {
    t1 = 1;
    if (s != t) t1++;
    t2 = cal_d(s + 1, t - 1, m + t1);
    ch_max(ret, t2);
  }
  if (m == 0) {
    for (i = s; i < t; ++i) {
      t0 = cal_d(s, i, 0);
      t1 = cal_d(i + 1, t, 0);
      ch_max(ret, t0 + t1);
    }
  } else {
    for (i = s; i < t; ++i) {
      t0 = cal_d(s, i, m);
      t1 = cal_f(i + 1, t, 0);
      if (t1 != -1) ch_max(ret, t0 + t1);
      t0 = cal_f(s, i, 0);
      t1 = cal_d(i + 1, t, m);
      if (t0 != -1) ch_max(ret, t0 + t1);
    }
  }
  return ret;
}
int main() {
  int i, j, k, t, nc = 0;
  while (scanf("%d", &n) != EOF) {
    a[0] = 0;
    for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
    scanf("%s", str);
    memset(d, 127, sizeof(d));
    memset(f, 127, sizeof(f));
    cal_d(0, n - 1, 0);
    int ans = d[0][n - 1][0];
    printf("%d\n", ans);
  }
  return 0;
}
