#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int a[(150 + 10)];
char s[(150 + 10)];
int f[(150 + 10)][(150 + 10)][(150 + 10)];
int g[(150 + 10)];
void update(int &u, int v) {
  if (v < 0) return;
  u = max(u, v);
}
void update(int &u, int a, int b) {
  if (a < 0 || b < 0) return;
  u = max(u, a + b);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("%s", s + 1);
  memset(f, -1, sizeof f);
  for (int i = 1; i <= n; ++i) {
    f[i][i - 1][0] = 0;
    f[i][i][1] = 0;
  }
  for (int len = 1; len <= n; ++len) {
    for (int i = 1; i + len - 1 <= n; ++i) {
      int j = i + len - 1;
      for (int l = 0; l <= len; ++l) {
        if (s[i] == s[j] && l >= 2) update(f[i][j][l], f[i + 1][j - 1][l - 2]);
        for (int k = i; k < j; ++k)
          update(f[i][j][l], f[i][k][l], f[k + 1][j][0]),
              update(f[i][j][l], f[i][k][0], f[k + 1][j][l]);
        update(f[i][j][0], f[i][j][l], a[l]);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    g[i] = g[i - 1];
    for (int j = 1; j <= i; ++j) update(g[i], g[j - 1], f[j][i][0]);
  }
  printf("%d\n", g[n]);
}
