#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 155;
int n, G[maxn][maxn], H[maxn][maxn], F[maxn][maxn][maxn];
int a[maxn];
char s[maxn];
void upd(int &x, int y, int z) {
  if (~y && ~z) x = max(x, y + z);
}
int main() {
  n = rd();
  for (int i = 1; i <= (int)n; i++) a[i] = rd();
  scanf("%s", s + 1);
  memset(G, -1, sizeof G), memset(F, -1, sizeof F);
  for (int i = 1; i <= (int)n; i++)
    G[i][i] = F[i][i][0] = a[1], F[i][i][1] = 0, H[i][i] = max(a[1], 0);
  for (int i = 0; i <= (int)n; i++) F[i + 1][i][0] = G[i + 1][i] = 0;
  for (int _ = 2; _ <= (int)n; _++)
    for (int l = 1; l <= (int)n - _ + 1; l++) {
      int r = l + _ - 1;
      for (int len = 0; len <= (int)_; len++) {
        if (len == 0 && s[l] == s[r])
          for (int i = 0; i <= (int)_ - 2; i++)
            upd(F[l][r][len], F[l + 1][r - 1][i], a[i + 2]);
        if (len == 1)
          for (int i = l; i <= (int)r; i++)
            upd(F[l][r][len], G[l][i - 1], G[i + 1][r]);
        for (int i = l; i <= (int)r - 1; i++)
          upd(F[l][r][len], G[l][i], F[i + 1][r][len]);
        for (int i = l + 1; i <= (int)r; i++)
          upd(F[l][r][len], F[l][i - 1][len], G[i][r]);
        if (len >= 2 && s[l] == s[r])
          upd(F[l][r][len], F[l + 1][r - 1][len - 2], 0);
      }
      for (int len = 0; len <= (int)_; len++)
        upd(G[l][r], F[l][r][len], a[len]);
      for (int i = l; i <= (int)r - 1; i++) upd(H[l][r], H[l][i], H[i + 1][r]);
      upd(H[l][r], G[l][r], 0);
    }
  rt(H[1][n]);
}
