#include <bits/stdc++.h>
using namespace std;
const int maxn = 160;
int g[maxn][maxn][maxn], f[maxn][maxn], a[maxn], n, ans[maxn];
char s[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) a[i] = -1e9;
  }
  scanf("%s", s + 1);
  memset(f, -0x3f, sizeof(f));
  memset(g, -0x3f, sizeof(g));
  for (int i = 1; i <= n; i++) {
    f[i][i] = a[1];
    g[i][i][1] = 0;
  }
  for (int i = 0; i <= n; i++) f[i + 1][i] = 0;
  for (int i = 2; i <= n; i++)
    for (int l = 1; l + i - 1 <= n; l++) {
      int r = l + i - 1;
      if (s[l] == s[r]) {
        g[l][r][2] = max(g[l][r][2], f[l + 1][r - 1]);
        for (int k = 3; k <= i; k++)
          g[l][r][k] = max(g[l][r][k], g[l + 1][r - 1][k - 2]);
      }
      for (int k = l; k < r; k++)
        for (int lk = 1; lk <= k - l + 1; lk++)
          g[l][r][lk] = max(g[l][r][lk], g[l][k][lk] + f[k + 1][r]);
      for (int k = l + 1; k <= r; k++)
        for (int lk = 1; lk <= r - k + 1; lk++)
          g[l][r][lk] = max(g[l][r][lk], g[k][r][lk] + f[l][k - 1]);
      for (int k = 1; k <= i; k++) f[l][r] = max(f[l][r], g[l][r][k] + a[k]);
    }
  for (int i = 1; i <= n; i++) {
    ans[i] = ans[i - 1];
    for (int j = 1; j <= i; j++) ans[i] = max(ans[i], ans[j - 1] + f[j][i]);
  }
  printf("%d\n", ans[n]);
  return 0;
}
